对于使用 Url 路由 访问页面的 ASP.NET 应用程序,IIS可能会显示404,403之类的错误代码,而且排除了代码问题(本地运行正常),那么就可以加下面这句话:
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>
原因:Url 路由是由 UrlRoutingModule 这个模块来处理的。在某些 IIS 版本中,并不会将所有请求交给 UrlRoutingModule 处理,所以,我们可以在 Web.config 中进行以上设置。
下面这句话也可以奏效,但不建议使用, 因为性能会浪费, 还有一些静态文件的请求可能会被要求验证 (比如图片是可以含有 & 符号的, 如果设置了这个, 就会被验证成 invalid 了)
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>