Seb Nilsson
Seb Nilsson

Reputation: 26408

ASP.NET MVC: Making routes/URLs IIS6 and IIS7-friendly

I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7 and as we all know, IIS6 needs the ".mvc"-naming in the URL.

Will this code work to make sure it works on all IIS-versions? Without having to make special adjustments in code, global.asax or config-files for the different IIS-versions.

bool usingIntegratedPipeline = HttpRuntime.UsingIntegratedPipeline;

routes.MapRoute(
    "Default",
    usingIntegratedPipeline ?
        "{controller}/{action}/{id}" : "{controller}.mvc/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

Update: Forgot to mention. No ISAPI. Hosted website, no control over the IIS-server.

Upvotes: 3

Views: 1807

Answers (2)

user19264
user19264

Reputation: 491

That should fix the .mvc problem since the integrated pipeline is IIS7 strictly. But remember to change settings on the IIS7 website to use "2.0 Integrated Pipeline" otherwhise it will return false aswell. Also ofcouse setup the mapping of .mvc to the asp.net isapi dll, but Im guessing that you already know this.

Some small suggestions on other things you might need to remember when deploying MVC applications on IIS6 that I found useful: http://msmvps.com/blogs/omar/archive/2008/06/30/deploy-asp-net-mvc-on-iis-6-solve-404-compression-and-performance-problems.aspx

Upvotes: 3

alex
alex

Reputation: 75945

You can use an ISAPI filter to rewrite URLs which will allow you to have the nice URLs while still on IIS 6.

Look, for example, here

Upvotes: 0

Related Questions