asp.net-mvc 在 MVC 网站上获取 404 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5068770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:55:02  来源:igfitidea点击:

Getting 404 error on MVC web-site

asp.net-mvcasp.net-mvc-2iis-7

提问by RB.

I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site deployed to it. The website was built in Visual Studio 2008, targeting .NET 3.5, and IIS 5.1 has been successfully configured to run it as well, for local testing.

我在 Windows Server 2008 上有一个 IIS7.5 网站,其中部署了一个 ASP.NET MVC2 网站。该网站是在 Visual Studio 2008 中构建的,针对 .NET 3.5,并且 IIS 5.1 已成功配置为运行它,用于本地测试。

However, whenever I try and navigate to a page running in IIS7, I get a 404 error.

但是,每当我尝试导航到在 IIS7 中运行的页面时,都会收到 404 错误。

I have checked the following things:

我检查了以下几件事:

  • There is no corresponding 404 log entry in IIS logs.
    • Actually, there are404 entries in the IIS log.
  • The application pool for the web-site is set to use the Integrated pipeline.
  • The "customErrors" mode is set to off.
  • .NET 3.5 SP1 is installed
  • ASP.NET MVC 2 is installed
  • I've used MVC Diagnostics to confirm all MVC DLLs are being found.
  • ASP.NET is enabled in IIS, which we've demonstrated by running the MVC Diagnostics page.
  • KB 2023146 did highlight that HTTP Redirection was off, so we've turned it on, but no joy.
  • IIS 日志中没有对应的 404 日志条目。
    • 实际上,IIS 日志中404 个条目。
  • 网站的应用程序池设置为使用集成管道。
  • “customErrors”模式设置为关闭。
  • .NET 3.5 SP1 已安装
  • 已安装 ASP.NET MVC 2
  • 我已经使用 MVC 诊断来确认所有 MVC DLL 都被找到了。
  • ASP.NET 在 IIS 中启用,我们已经通过运行 MVC 诊断页面进行了演示。
  • KB 2023146 确实强调了 HTTP 重定向已关闭,因此我们已将其打开,但并不高兴。

EDITOk, so we've installed the world's simplest MVC application (the one which is created when you create a new MVC2 project in Visual Studio), and we are still getting 404s on any page we try and access - e.g. <my_server>/Home/Aboutwill generate a 404.

编辑好的,所以我们已经安装了世界上最简单的 MVC 应用程序(当您在 Visual Studio 中创建新的 MVC2 项目时创建的应用程序),并且我们仍然在我们尝试访问的任何页面上获得 404 - 例如 <my_server>/Home/About将生成一个 404 .

Any ideas will be greatly appreciated!

任何想法将不胜感激!

采纳答案by RB.

We finally nailed this issue by exporting the IIS configuration of a working server, and comparing it to ours.

我们最终通过导出工作服务器的 IIS 配置并将其与我们的进行比较来解决这个问题。

It was a really obscure setting which had been changed from the default.

这是一个非常晦涩的设置,已从默认设置更改。

IIS ROOT → request Filtering → Filename Extensions Tab → Edit Feature Settings → Allow unlisted file name extensions

IIS ROOT → 请求过滤 → 文件扩展名选项卡 → 编辑功能设置 → 允许未列出的文件扩展名

This should be ticked.

这个应该打勾。

This can be set at the IIS level, or the site-level.

这可以在 IIS 级别或站点级别设置。

Screenshot of IIS showing location of Request Filtering option

显示请求过滤选项位置的 IIS 屏幕截图

回答by Sam Shiles

This is quite often caused by the following missing from the web.config:

这通常是由 web.config 中缺少以下内容引起的:

<system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/> 

回答by Jakub Konecki

Do you have a problem with just 1 page or the whole site is not working?

您是否遇到只有 1 个页面或整个网站无法运行的问题?

A) 1 page

A) 1 页

  • You can use RouteDebuggerto verify if the route is matched correctly

B) Whole site

B) 整个站点

  • I assume you're using Windows Server - check if ASP.NET is enabled in IIS - it's disabled by default, I believe.

  • You can use MvcDiagnosticspage to check if all dlls are deployed properly.

  • Are you running in IIS7 integrated mode? Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6)

  • Make sure your Web.config tag is configured correctly.

  • 我假设您使用的是 Windows Server - 检查是否在 IIS 中启用了 ASP.NET - 默认情况下它是禁用的,我相信。

  • 您可以使用MvcDiagnostics页面来检查所有 dll 是否已正确部署。

  • 您是否在 IIS7集成模式下运行?IIS7 的经典模式不会自动将无扩展名的 URL 映射到 ASP.NET(很像 IIS6)

  • 确保您的Web.config标记配置正确。

回答by John Mathis

Glad that fixed your problem. Others researching this issue should take note of the extensionless URL hotfix: http://support.microsoft.com/kb/980368

很高兴解决了您的问题。研究此问题的其他人应注意无扩展名 URL 修补程序:http: //support.microsoft.com/kb/980368

回答by Lanklaas

If none of the other solutions here solved your issue, check that you have the

如果这里的其他解决方案都没有解决您的问题,请检查您是否拥有

Global.asax

全球.asax

file in your website. This solved the issue for me.

文件在您的网站。这为我解决了这个问题。

回答by Darin Dimitrov

Checkout if KB 2023146applies to your scenario. Also try requesting directly a controller action: /yoursitename/home/index

检查KB 2023146 是否适用于您的方案。还可以尝试直接请求控制器操作:/yoursitename/home/index

回答by Kiki

Apparently this can have many different causes.

显然,这可能有许多不同的原因。

For us, the problem was that the DNS entry was configured for two IP addresses, but the IIS configuration would only listen to one of them. So we got unpredictable results, sometimes it would work, sometimes a few files (css, etc) would not load, and sometimes the whole page would not load.

对我们来说,问题是 DNS 条目被配置为两个 IP 地址,但 IIS 配置只会侦听其中一个。所以我们得到了不可预测的结果,有时它会起作用,有时一些文件(css 等)不会加载,有时整个页面都不会加载。

回答by Michal B.

For me it was all about installing .NET Framework 4.6.1 on the server (my app was targeting that version)

对我来说,这一切都是关于在服务器上安装 .NET Framework 4.6.1(我的应用程序针对该版本)

回答by Rez.Net

My Hosting company fixed this for me by doing this (I removed the original password value of course).

我的托管公司通过这样做为我解决了这个问题(我当然删除了原始密码值)。

  <system.webServer>
    <security>
      <authentication>
        <anonymousAuthentication password="<password>" />
      </authentication>
    </security>
  </system.webServer>

回答by Jeremy Thompson

Typically I encounter this issue when there is a Routing problem. I compare a working vs non-working to resolve it.

通常,当存在路由问题时,我会遇到此问题。我比较了工作与非工作来解决它。



Today however I accidentially created a Virtual Directory in IIS.

然而今天我不小心在 IIS 中创建了一个虚拟目录。

It has to be an Application, right click on the Virtual Directory (with a folder icon) -> Convert to Application:

它必须是一个应用程序,右键单击虚拟目录(带有文件夹图标)-> 转换为应用程序:

enter image description here

在此处输入图片说明