Search code examples
c#iis-7.5asp.net-mvc-routing

ASP.NET MVC Routing - add .html extension to routes


i am pretty new to MVC and Routing and i was asked to modify an app to use diffrent url's. a task that is a bit over me since i have no experience.

ok, lets talk a bit of code:

routes.MapRoute(
"CategoryBySeName", // Route name
"products/{SeName}", // URL with parameters
new { controller = "Catalog", action = "CategoryBySeName" }
);

this works as expected, but then the client wanted ".html" at the end of paths, so i changed:

"products/{SeName}", // URL with parameters

to:

"products/{SeName}.html", // URL with parameters

which fails ( IIS 404 page - MapRequestHandler) it seems like iis is trying to load a physical file with that name instead of passing it to the application.

Similar: ASP.NET MVC Routing to start at html page (not answered, Not duplicate)


Solution

  • You're guess that an IIS handler is probably grabbing the request prior to MVC is likely correct.

    Assuming IIS 7: http://technet.microsoft.com/en-us/library/cc770990(v=ws.10).aspx

    You need to edit the .html handler in IIS to use ASP.NET.

    You can find it in the website properties under the home directory tab in app configuration in the mappings section in II6.

    Something along the lines of (version may be different): C:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll is what you need to handle the .html files.