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 know 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.
-
1Can you show us the routes and their respective Action methods around this issue?George Stocker– George Stocker2011年07月18日 15:39:11 +00:00Commented Jul 18, 2011 at 15:39
-
I am a bit confused as to what is causing a 302 to /Toons/List/ when requesting /Toons/List. +1 for posting the routes or whatever is causing the 302 and why it is expected.Jason Capriotti– Jason Capriotti2011年08月04日 21:01:06 +00:00Commented Aug 4, 2011 at 21:01
-
problem went away at some point, I don't know what was causing that.THX-1138– THX-11382011年08月04日 22:19:24 +00:00Commented Aug 4, 2011 at 22:19
3 Answers 3
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.
Comments
Can you tell IIS to return a 307 instead of a 302?
Comments
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/