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

≯℡__Kan透↙ 提交于 2019-12-09 03:43:33

问题


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:


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.



来源:https://stackoverflow.com/questions/29272618/how-to-add-extension-html-in-url-asp-net-mvc-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!