部署时提供404的MVC 4应用程序 [英] MVC 4 application giving a 404 when deployed

查看:72
本文介绍了部署时提供404的MVC 4应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用.NET 4.5的ASP.NET MVC 4项目,我正在尝试使用Visual Studio 2012将其发布到IIS 7.0.当我在IIS Express中调试应用程序时,一切运行都很好.当我将其发布到服务器时,MVC请求返回404.我在站点上有几个aspx页面,它们都可以正常工作.以下是我的路由方案.这是样板代码:

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

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

谢谢.

我明白了!我必须在web.configsystem.webServer中添加以下内容:

<modules runAllManagedModulesForAllRequests="true"/>

有人可以告诉我为什么吗?

解决方案

此参考资料可能会有所帮助:

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

以前必须将runAllManagedModulesForAllRequests设置为true以支持路由.但是,使用Service Pack更新IIS 7后,可以在使用ASP.NET路由时将runAllManagedModulesForAllRequests的值设置为false或省略."/p>

(显然,首先要仔细考虑安装IIS或Windows Service Pack)

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?

解决方案

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)

这篇关于部署时提供404的MVC 4应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆