如何在asp.net MVC 4 URL中添加扩展名.html? [英] How to add extension .html in url asp.net mvc 4?

查看:113
本文介绍了如何在asp.net MVC 4 URL中添加扩展名.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网址:
http:// localhost:1714 / Message / Index



我要显示:
http:// localhost:1714 / Message / Index.html



我该怎么办?

解决方案

您需要修改Web.config才能将HTML文件的请求映射到TransferRequestHandler。 / p>

像这样:

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

这是此处



并将其放入您的RouteConfig:

  public static void RegisterRoutes (RouteCollection路由)
{
...
route.MapRoute( Default, {controller} / {action} .html,新的{controller = Home,action = 索引});
...
}

比访问 http:// localhost :{port} /Home/Index.html会将您发送到您的主页。


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

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

How can I do it?

解决方案

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.

这篇关于如何在asp.net MVC 4 URL中添加扩展名.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆