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

后端 未结 1 1323
借酒劲吻你
借酒劲吻你 2021-01-20 05:43

I have the url: http://localhost:1714/Message/Index

I want to show: http://localhost:1714/Message/Index.html

How can I do it?

相关标签:
1条回答
  • 2021-01-20 06:15

    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.

    0 讨论(0)
提交回复
热议问题