在 IIS 7.0/Windows Server 2008 上为 ASP.NET MVC 3 应用程序获取 404.0 错误 [英] Getting 404.0 error for ASP.NET MVC 3 app on IIS 7.0 / Windows Server 2008

查看:18
本文介绍了在 IIS 7.0/Windows Server 2008 上为 ASP.NET MVC 3 应用程序获取 404.0 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 ASP.NET MVC 3 应用程序部署到 Windows 2008 x64 服务器(显然运行 IIS 7.0),而 IIS 似乎不希望正确提供内容.所有请求都会导致 404.0 错误,因为请求与任何处理程序都不匹配,并且 IIS 正在尝试使用 StaticFile 处理程序来处理请求.该问题似乎与 .NET 4.0 有关,因为我有一个 MVC 2 应用程序在为 .NET 2.0 运行时配置的应用程序池中运行良好.

I am attempting to deploy an ASP.NET MVC 3 application to a Windows 2008 x64 server (running IIS 7.0 obviously), and IIS does not want to seem to serve up the content properly. All requests are resulting in a 404.0 error, because the requests are not matching any handler and IIS is attempting to use the StaticFile handler to serve up the requests. The issue seems to be related to .NET 4.0, as I have an MVC 2 application running just fine in an app pool that is configured for the .NET 2.0 runtime.

我在将相同的应用程序部署到 Windows 7 和 Windows Server 2008 R2 上的 IIS 7.5 服务器时没有遇到任何问题.

I have had no issues deploying this same application to IIS 7.5 servers both on Windows 7 and Windows Server 2008 R2.

在部署之前,2008 服务器没有安装 .NET 4.0 或 ASP.NET MVC 3,所以这里是我在部署应用程序之前执行的步骤:

Prior to deployment, the 2008 server did not have .NET 4.0 or ASP.NET MVC 3 installed, so here are the steps I undertook prior to deploying the application:

  1. 已安装 .NET 4.0
  2. 运行 aspnet_regiis.exe(来自 Framework64/v4.0.30319 文件夹)
  3. 使用网络平台安装程序安装了 ASP.NET MVC 3
  4. 应用 MS 更新 KB980368 以启用某些 IIS 7.0 或 IIS 7.5 处理程序处理 URL 不以句点结尾的请求
  1. Installed .NET 4.0
  2. Ran aspnet_regiis.exe (from the Framework64/v4.0.30319 folder)
  3. Installed ASP.NET MVC 3 using the web platform installer
  4. Applied MS update KB980368 to enable certain IIS 7.0 or IIS 7.5 handlers to handle requests whose URLs do not end with a period

对应用程序中的静态资源(JavaScript 文件、图像等)的请求顺利通过,但对 MVC 操作的任何请求都会失败并显示 404.0 错误.我注意到 IIS 正在使用 StaticFile 处理程序来处理这些请求,这显然是不正确的.据我所知,ASP.NET 4.0 处理程序(即 ExtensionlessUrl-ISAPI-4.0* 处理程序)已正确定义,所以我不知道为什么/如何不由这些处理程序之一处理请求,并且会落入所有一直到 StaticFile 处理程序.

Requests to static resources in the application (JavaScript files, images, etc) go through without a hitch, but any request to an MVC action fails with a 404.0 error. I have noticed that IIS is using the StaticFile handler to handle these requests, which is obviously incorrect. The ASP.NET 4.0 handlers (i.e. ExtensionlessUrl-ISAPI-4.0* handlers) are properly defined as far as I can tell, so I have no idea why/how the request would not be handled by one of these handlers and would fall all the way down to the StaticFile handler.

我还看到了以下 MS 知识库文章,其中提到您应该确保 HTTP 重定向和静态内容压缩在您遇到 404 错误的服务器上启用/安装.我查了一下,我的服务器已经启用了这两个功能.我什至尝试删除并重新安装这些功能无济于事.

I also came across the following MS knowledge base article which mentions that you should ensure HTTP Redirection and Static Content Compression are enabled/installed on the server where you are experiencing the 404 errors. I checked, and both features were already enabled for my server. I even tried removing and reinstalling the features to no avail.

在这一点上,我完全不知道为什么这不能正常工作.我已经能够在 2 个不同的 IIS 7.0 服务器上复制该问题.我错过了什么?

At this point I am completely out of ideas for why this is not working properly. I have been able to replicate the issue on 2 different IIS 7.0 servers. What am I missing?

推荐答案

问题最终是我的代码完全依赖于仅在 IIS 7.5 中可用的自动启动功能.我能够在 IIS 中的失败请求跟踪功能的帮助下发现问题,现在我已经修改了我的 global.asax.cs 文件,以便应用程序将被正确初始化,无论它是如何/何时加载的.

The issue ended up being that my code was completely relying on the auto-start functionality that is available only in IIS 7.5. I was able to discover the issue with the help of the Failed Request Tracing feature in IIS, and I have now modified my global.asax.cs file so that the application will be properly initialized, regardless of how/when it is loaded.

这篇关于在 IIS 7.0/Windows Server 2008 上为 ASP.NET MVC 3 应用程序获取 404.0 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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