ASP.NET MVC Routing - Add .HTML Extension to Routes

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

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.

How to add extension .html in url asp.net mvc 4?

You need to modify Web.config to map requests for your HTML files to TransferRequestHandler.

like so:

<system.webServer>
...
<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
...
</system.webServer>

This is explained here by Jon Galloway.

And put this to your RouteConfig:

public static void RegisterRoutes(RouteCollection routes)
{
...
routes.MapRoute("Default", "{controller}/{action}.html", new { controller = "Home", action = "Index" });
...
}

Than accessing http://localhost:{port}/Home/Index.html will send you to your Home page.

ASP.NET MVC Route Doesn't Work With .html Extension

I've added HtmlFileHandler to my web.config. And .html routes work now.

<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>


Related Topics



Leave a reply



Submit