Balugu Balugu - 1 year ago 97
ASP.NET (C#) Question

How to add extension .html in url mvc 4?

I have the url:


I want to show:

How can I do it?

Answer Source

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

like so:

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

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.