Note: I have done hours of digging for the answer, and couldn't find one.
注意:我已经花了几个小时挖掘答案,却找不到答案。
I have an ASP.NET MVC (2.0) application, hosted on IIS7 (integrated mode).
我有一个ASP.NET MVC(2.0)应用程序,托管在IIS7(集成模式)上。
When GET request is made to /Toons/List
- I get a redirect (302) to /Toons/List/
which is expected.
当向/ Toons / List发出GET请求时 - 我得到一个重定向(302)到/ Toons / List /这是预期的。
THE PROBLEM
But when I send a POST request, say to /Toons/Add
(notice no trailing slash) server returns, again, redirect (302) to /Toons/Add/
. At this point, FireFox, mistakenly sends GET request to that redirect-to URL. I.e. [GET] /Toons/Add/
instead of [POST] /Toons/Add/
. This is incorrect, but known behavior. Since there is no [GET] on /Toons/Add/
- I get resource not found (404).
问题但是当我发送POST请求时,请说/ Toons / Add(注意没有尾随斜杠)服务器再次返回,重定向(302)到/ Toons / Add /。此时,FireFox错误地将GET请求发送到该重定向到URL。即[GET] / Toons / Add /而不是[POST] / Toons / Add /。这是不正确的,但已知的行为。由于没有[GET] on / Toons / Add / - 我找不到资源(404)。
I host my app with webhost4life and have no access to IIS7, which limits my use of URL rewriting and using modules (I'm working with them to work around this). But even than, is ISAPI the best way to go? I don't know it enough to feel good about doing it this way.
我使用webhost4life托管我的应用程序并且无法访问IIS7,这限制了我对URL重写和使用模块的使用(我正在与他们一起解决这个问题)。但是,ISAPI是最好的方式吗?我不知道以这种方式做到这一点感觉良好。
This got to be a common problem, I'm surprised I couldn't find an easy solution for this.
这是一个常见的问题,我很惊讶我找不到一个简单的解决方案。
Is there a solution that doesn't involve using .aspx / .mvc suffix, and URL rewriting?
Out of those two, if I have to, which one should I prefer?
是否有一个解决方案不涉及使用.aspx / .mvc后缀和URL重写?在这两个中,如果必须,我应该选择哪一个?
Any ideas / suggestions?
有什么想法/建议吗?
EDIT:
I have read http://www.hanselman.com/blog/ASPNETMVCAndTheNewIIS7RewriteModule.aspx, as I said, I'm trying to find an easier solution, a "Just Work" option.
编辑:我已经阅读http://www.hanselman.com/blog/ASPNETMVCAndTheNewIIS7RewriteModule.aspx,正如我所说,我正在努力寻找一个更简单的解决方案,一个“正常工作”选项。
EDIT:
I have seen solution with appending slash (/
) to every URL, again, doesn't seem to be most elegant solution.
编辑:我已经看到解决方案与每个URL附加斜杠(/),再次,似乎不是最优雅的解决方案。
3 个解决方案
#1
1
You should be using the actual URL/route when linking. If you are unable to remove the slash from the route because of a limitation of the hosting environment or 2.0 version of the MVC framework, you need to include the trailing slash in your URLs.
您应该在链接时使用实际的URL /路由。如果由于托管环境或2.0版MVC框架的限制而无法从路由中删除斜杠,则需要在URL中包含尾部斜杠。
Relying on the server to redirect every URL will increase server processing time and page load time.
依靠服务器重定向每个URL将增加服务器处理时间和页面加载时间。
#2
0
Can you tell IIS to return a 307 instead of a 302?
你能告诉IIS返回307而不是302吗?
#3
0
Have you set the action method in the controller to accept post HttpVerbs? You can also try setting up a route in the Global.asax for the /Toons/Add so MVC isn't reading it as /Controller/Method/
你有没有在控制器中设置动作方法来接受HttpVerbs的帖子?您还可以尝试在Global.asax中为/ Toons / Add设置路由,以便MVC不将其读取为/ Controller / Method /
#1
1
You should be using the actual URL/route when linking. If you are unable to remove the slash from the route because of a limitation of the hosting environment or 2.0 version of the MVC framework, you need to include the trailing slash in your URLs.
您应该在链接时使用实际的URL /路由。如果由于托管环境或2.0版MVC框架的限制而无法从路由中删除斜杠,则需要在URL中包含尾部斜杠。
Relying on the server to redirect every URL will increase server processing time and page load time.
依靠服务器重定向每个URL将增加服务器处理时间和页面加载时间。
#2
0
Can you tell IIS to return a 307 instead of a 302?
你能告诉IIS返回307而不是302吗?
#3
0
Have you set the action method in the controller to accept post HttpVerbs? You can also try setting up a route in the Global.asax for the /Toons/Add so MVC isn't reading it as /Controller/Method/
你有没有在控制器中设置动作方法来接受HttpVerbs的帖子?您还可以尝试在Global.asax中为/ Toons / Add设置路由,以便MVC不将其读取为/ Controller / Method /