Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 681
THX-1138 Avatar asked Jan 26 '10 19:01

THX-1138


1 Answers

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.

like image 64
Brandon Gano Avatar answered Oct 14 '22 14:10

Brandon Gano