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

后端 未结 1 1325
借酒劲吻你
借酒劲吻你 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:

    
        ...
        
          
        
        ...
      
    

    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)
提交回复
热议问题