ASP.NET MVC路由不适用于.html扩展名

Yar*_*icx 5 c# asp.net asp.net-mvc routes asp.net-mvc-4

我使用ASP.NET MVC开发了一个Web应用程序。我的路线有问题。

我需要这样的路线。 http://localhost/content-name/23.html

我为此定义了一条路线

//i need this route but it's not work
routes.MapRoute(
"GetContent",
"{sefLink}/{contentId}.html",
new { controller = "Content", action = "GetContent" },
new[] { "CanEcomm.Controllers" });
Run Code Online (Sandbox Code Playgroud)

但是这条路线不起作用。IIS正在向我显示404页面。当我删除.html扩展名时,路由可行。

//this route is working. i just remove ".html" extension
routes.MapRoute(
    "GetContent",
    "{sefLink}/{contentId}",
    new { controller = "Content", action = "GetContent" },
    new[] { "CanEcomm.Controllers" });
Run Code Online (Sandbox Code Playgroud)

我该如何解决?谢谢

Yar*_*icx 5

我已经将HtmlFileHandler添加到我的web.config中。.html路由现在可以使用。

<handlers>
  <add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>    
Run Code Online (Sandbox Code Playgroud)