开发者

ASP.NET MVC + IIS7 + FireFox : trailing slash in URL

开发者 https://www.devze.com 2022-12-17 23:41 出处:网络
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).

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).

When GET request is made to /Toons/List - I get a redirect (302) to /Toons/List/ which is expected.

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).

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 k开发者_如何学JAVAnow it enough to feel good about doing it this way.

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?

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.

EDIT:

I have seen solution with appending slash (/) to every URL, again, doesn't seem to be most elegant solution.


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.

Relying on the server to redirect every URL will increase server processing time and page load time.


Can you tell IIS to return a 307 instead of a 302?


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号