ASP.NET MVC - MVC 5 on IIS 7

在 IIS 7 使用 ASP.NET MVC 5,Routing 功能會無法正常運作,會看到 403 或是 404 頁面。


這邊可以在 Web.Config 的 modules 這邊加上 runAllManagedModulesForAllRequests="true" 設定,並為網站加上 UrlRoutingModule-4.0 模組。

1
2
3
4
5
6
7
8
...
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
...
<remove name="UrlRoutingModule-4.0"></remove>
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition=""></add>
</modules>
...


沒意外的話就會運作正常了。