MVC 4 application giving a 404 when deployed

霸气de小男生 提交于 2020-01-03 08:58:32

问题


I have an ASP.NET MVC 4 project using .NET 4.5 that I am trying to publish to IIS 7.0 using Visual Studio 2012. When I debug the application in IIS Express everything works wonderfully. When I publish it to the server, the MVC requests return 404. I have a few aspx pages on the site and they all work fine. Below is my routing scheme. It is boilerplate code:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

Thanks.

Edits:

I got it! I had to add the following to system.webServer in my web.config:

<modules runAllManagedModulesForAllRequests="true"/>

Can anyone tell me why this is?


回答1:


This reference may help:

https://www.iis.net/configreference/system.webserver/modules

"runAllManagedModulesForAllRequests previously had to be set to true to support routing. However, once IIS 7 has been updated with a Service Pack, the value of runAllManagedModulesForAllRequests can be set to false or omitted when working with ASP.NET routing."

(obviously installing an IIS or Windows service pack needs careful consideration first)




回答2:


<modules runAllManagedModulesForAllRequests="true"/>

Reference : Here



来源:https://stackoverflow.com/questions/16178821/mvc-4-application-giving-a-404-when-deployed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!