【问题标题】:Map legacy htm files to equivalent action将遗留 htm 文件映射到等效操作
【发布时间】:2013-05-03 13:28:21
【问题描述】:

我正在尝试执行以下操作:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes){
    {
        //other stuff
        routes.MapRoute(
            name: "MyRoute", 
            url: "test.htm", 
            defaults: new { controller = "Controller", action = "Test" });
    }
}

但 IIS 在尝试检索 example.com/test.htm 的静态文件时返回 404。

怎样才能得到想要的效果?

【问题讨论】:

  • 另外,我尝试将它放在RegisterRoutes 方法的顶部。结果还是一样。

标签: asp.net-mvc iis asp.net-mvc-routing


【解决方案1】:

最终对我有用的解决方案是执行以下操作:

<system.webServer>
    <handlers>
        <add name="htm to asp" path="*.htm" verb="*" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" preCondition="integratedMode" />
    </handlers>
</system.webServer>

【讨论】:

    【解决方案2】:

    这是因为 MVC 路由很难处理句点。如果您使用的是 .NET 4,则可以放置

    <httpRuntime relaxedUrlToFileSystemMapping="true"/>
    

    在您的 web.config 文件中。

    这里是解释和更多信息:http://haacked.com/archive/2010/04/29/allowing-reserved-filenames-in-URLs.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 2011-05-22
      相关资源
      最近更新 更多