如何在 url asp.net mvc 4 中添加扩展名 .html?
How to add extension .html in url asp.net mvc 4?
我有url:
http://localhost:1714/Message/Index
我要展示:
http://localhost:1714/Message/Index.html
我该怎么做?
您需要修改 Web.config 以将对 HTML 文件的请求映射到 TransferRequestHandler。
像这样:
<system.webServer>
...
<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
...
</system.webServer>
Jon Galloway here 解释了这一点。
并将其放入您的 RouteConfig:
public static void RegisterRoutes(RouteCollection routes)
{
...
routes.MapRoute("Default", "{controller}/{action}.html", new { controller = "Home", action = "Index" });
...
}
访问 http://localhost:{端口}/Home/Index。html 会将您带到您的主页。
我有url:
http://localhost:1714/Message/Index
我要展示:
http://localhost:1714/Message/Index.html
我该怎么做?
您需要修改 Web.config 以将对 HTML 文件的请求映射到 TransferRequestHandler。
像这样:
<system.webServer>
...
<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
...
</system.webServer>
Jon Galloway here 解释了这一点。
并将其放入您的 RouteConfig:
public static void RegisterRoutes(RouteCollection routes)
{
...
routes.MapRoute("Default", "{controller}/{action}.html", new { controller = "Home", action = "Index" });
...
}
访问 http://localhost:{端口}/Home/Index。html 会将您带到您的主页。