IIS 8.5 中的尾部斜线问题

trailing slash issue in IIS 8.5

我们正在将 ASP.NET 项目从 IIS6 (Win Server 2003) 移动到 IIS 8.5(Win Server 2012 R2)。该项目有一些使用以下路由的 MVC 组件。

routes.MapRoute("simple", "{controller}.mvc/{action}/{id}");
routes.MapRoute(
                "Default", 
                "{controller}.mvc/{action}/{id}"                            
                new { controller = "Home", action = "Index", id = "" }
            );

因此 MyDemoController 的调用将被 MyDemo.mvc

访问

现在会发生什么,当我将 url 用作 MyDemo.mvc/ 时,它可以工作,但是当我使用 MyDemo.mvc 而不使用斜线时,它会抛出 404 错误。

这仅发生在已部署的服务器中。在我们使用 IIS7.5、Win 7 的本地机器上,它可以正常工作。

无法手动更改,因为站点地图文件中添加了很多 url,而我们的客户不赞成这种方法。

它是否特定于 IIS 版本或任何小的调整都可以解决问题?

看看下面的内容。我相信这是你的问题。它与 .mvc 扩展有关。

ASP.NET MVC - Routing - an action with file extension

Dots in URL causes 404 with ASP.NET mvc and IIS

The problem is that IIS will handle the .mvc file as a static file and will by default not route the hypothetical .mvc file through your MVC application. IIS handles the request and your MVC code never gets a change to route to this file.

总而言之,以下是使 .mvc 文件正常工作的配置:

<system.webServer>
  <handlers>
    <add name="MVCFileHandler"
      path="*.mvc"
      verb="GET" type="System.Web.Handlers.TransferRequestHandler"
      preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0"  />
  </handlers>
</system.webServer>

至于它在 IIS7.5 上运行,Win 7 没有任何问题,而不是 IIS 8.5。

看看这个答案

Routing a url with extension in MVC4 won't work, tries to serve up static file

There is also <modules runAllManagedModulesForAllRequests="true"> but it doesn't seem to work for MVC4/IIS8 (used to be ok in MVC3/IIS7 IIRC). More info here. There is also a performance impact with this one as every request will route through the managed pipeline.

希望所有这些对您有所帮助