【问题标题】:ASP.NET MVC Route Doesn't Work With .html ExtensionASP.NET MVC 路由不适用于 .html 扩展
【发布时间】:2016-02-14 10:07:03
【问题描述】:

我使用 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" });

但是路线不通。 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" });

我该如何解决这个问题? 谢谢

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-4 routes


    【解决方案1】:

    我已将 HtmlFileHandler 添加到我的 web.config 中。 .html 路由现在可以工作了。

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

    【讨论】:

      猜你喜欢
      • 2012-03-09
      • 1970-01-01
      • 2014-02-09
      • 2018-01-07
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      相关资源
      最近更新 更多