【发布时间】:2018-05-15 00:40:38
【问题描述】:
我有一个 ASP.NET MVC 应用程序,该应用程序部署到 IIS 10 上的多个服务器。所有路由都在那里正常工作。
在 IIS 8.5 上,遵循 {controller}/{action}/{id} 的路由返回 404。如果将路由更改为 {controller}/{action}?id={id},则返回正确的结果带有 200 码。
是否必须启用 IIS 8.5 才能将 {controller}/{action}/{id} 正确映射到 MVC 控制器的设置?
我的路线配置:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
网页配置的相关部分:
<system.web>
<compilation targetFramework="4.6.1" />
<httpRuntime targetFramework="4.5" maxUrlLength="99999" maxQueryStringLength="99999" />
<customErrors mode="RemoteOnly" />
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="FormsAuthentication" />
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>
我已经尝试了this question 中的建议,但他们没有修复 404。
【问题讨论】:
-
您要访问的网址是什么?
-
example.com:8080/controller/action/id。这是一个内部 B2B 网站,因此您无法对其进行测试。
-
是您尝试使用的实际网址吗?您有一个名为
controllerController的控制器和一个名为action(int id)的操作方法? -
没有。控制器被命名为别的东西,动作也是如此。参数名为 id。
-
是的。正如我在帖子中提到的,此站点和这些操作特别适用于在 IIS 10/Windows Server 2016 上运行的同一 MVC 站点的多个其他实例。
标签: asp.net asp.net-mvc iis