visual-studio 无法在 IIS 7.5 上运行 ASP.NET MVC 2 Web 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2659544/
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-10-22 11:47:43  来源:igfitidea点击:

Can't run ASP.NET MVC 2 web app on IIS 7.5

visual-studio-2010visual-studioiisasp.net-mvc-2iis-7.5

提问by Portman

I'm trying to run an ASP.NET MVC 2 web application under IIS on Windows 7, but I get a 403.14 error. Here are the steps to reproduce:

我正在尝试在 Windows 7 上的 IIS 下运行 ASP.NET MVC 2 Web 应用程序,但出现 403.14 错误。以下是重现的步骤:

  1. Open Visual Studio 2010
  2. Create a new ASP.NET MVC 2 project called MvcApplication1
  3. Shift+F5 to run the app. You should see http://localhost:{random_port}/and the page will render correctly.
  4. Click on MvcApplication1, and select "Properties". Go to the "Web" section.
  5. Select "Use Local IIS Web server" and create a virtual directory.
  6. Save.
  7. Shift+F5 to run the app. You should see http://localhost/MvcApplication1/and an IIS error HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory..
  1. 打开 Visual Studio 2010
  2. 创建一个名为 MvcApplication1 的新 ASP.NET MVC 2 项目
  3. Shift+F5 运行应用程序。您应该会看到http://localhost:{random_port}/页面将正确呈现。
  4. 单击 MvcApplication1,然后选择“属性”。转到“Web”部分。
  5. 选择“使用本地 IIS Web 服务器”并创建一个虚拟目录。
  6. 保存。
  7. Shift+F5 运行应用程序。您应该会看到http://localhost/MvcApplication1/IIS 错误HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

It's clear that for whatever reason, ASP.NET routing is not working correctly.

很明显,无论出于何种原因,ASP.NET 路由都无法正常工作。

Things I've already thought of and tried:

我已经想到并尝试过的事情:

  • Verified that all IIS features are enabled in "Turn Windows features on or off".
  • Verified that the default website is configured to use .NET 4.0
  • Reassigned ASP.NET v4 scripmaps via aspnet_regiis -iin the v4.0.30319directory.
  • 验证在“打开或关闭 Windows 功能”中是否启用了所有 IIS 功能。
  • 验证默认网站配置为使用 .NET 4.0
  • 通过aspnet_regiis -iv4.0.30319目录中重新分配 ASP.NET v4 脚本。

Here's the most amazing part - this is on a just-builtmachine. New copy of Windows 7 x64 Ultimate, clean install of Visual Studio 2010 Premium, no other websites and no other work performed.

这是最令人惊奇的部分 - 这是在一台刚刚建造的机器上。Windows 7 x64 Ultimate 的新副本,Visual Studio 2010 Premium 的全新安装,没有其他网站,也没有执行其他工作。

Anything else I can try?

还有什么我可以尝试的吗?

Setting Visual Studio to use local IIS web server

将 Visual Studio 设置为使用本地 IIS Web 服务器

回答by Portman

Ok, this is resolved for me, by doing the following:

好的,通过执行以下操作,这对我来说已解决:

Running aspnet_regiis -iin the 32-bitdirectory c:\Windows\Microsoft.NET\Framework\v4.0.30319.

aspnet_regiis -i32 位目录中运行c:\Windows\Microsoft.NET\Framework\v4.0.30319

At this point, I don't understand why 64-bit mode isn't working, but I'm now unblocked. Hopefully this helps anyone else who is having this issue.

在这一点上,我不明白为什么 64 位模式不起作用,但我现在已解锁。希望这可以帮助其他遇到此问题的人。

回答by Tom Chantler

I had exactly the same issue, so thanks for your help.

我遇到了完全相同的问题,所以感谢您的帮助。

However... did you try running the aspnet_regiis -icommand in the Visual Studio 64 bit command prompt (with admin privileges)? When I did that it fixed it for the 64-bit mode.

但是...您是否尝试aspnet_regiis -i在 Visual Studio 64 位命令提示符(具有管理员权限)中运行该命令?当我这样做时,它修复了 64 位模式。

To clarify, I right clicked on Visual Studio x64 Win64 Command Prompt (2010)and chose Run as Administrator. Then I went here:

为了澄清,我右键单击Visual Studio x64 Win64 Command Prompt (2010)并选择以管理员身份运行。然后我去了这里:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

And did this: aspnet_regiis -i

并做到了这一点: aspnet_regiis -i

And now it works perfectly.

现在它可以完美运行。

回答by Rohan West

Also ensure that you configuration file has the following line otherwise the routing will not work.

还要确保您的配置文件具有以下行,否则路由将无法工作。

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

回答by Chris Herring

Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.

不要使用 runAllManagedModulesForAllRequests。您希望让 IIS 处理图像等资源。

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

Instead add the MVC routing module

而是添加MVC路由模块

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>

回答by JGilmartin

Another thing to note, make sure your application pool is set to integrated, not classic

还有一点要注意,确保你的应用程序池设置为集成的,而不是经典的

回答by Jeroen Ritmeijer

I had this same problem on IIS8 / Windows Server 2012. None of the many proposed solutions worked until I tried the following.

我在 IIS8/Windows Server 2012 上遇到了同样的问题。在我尝试以下之前,许多建议的解决方案都没有奏效。

dism /online /enable-feature /featurename:IIS-ASPNET45 /All

Without the '/All' switch it complained that a parent feature was not installed.

如果没有“/All”开关,它会抱怨未安装父功能。

The strange thing is that according to Windows' Turn Windows Features on or offfacility, asp.net 4.5 was already installed.

奇怪的是,根据 Windows 的“打开或关闭 Windows 功能”工具,已经安装了 asp.net 4.5。

There was no need to make any changes to the web.config, add or remove modules.

无需对 web.config 进行任何更改、添加或删除模块。

回答by Daniel Schaffer

I've always used the custom server setting in VS 2008, which still allows me to debug with no problems. Not sure if it works any differently in 2010

我一直在 VS 2008 中使用自定义服务器设置,它仍然允许我毫无问题地进行调试。不确定它在 2010 年的工作方式是否有所不同

回答by Charlie

I had these symptoms; My Global.asaxwas crashing. Fixed the crash, everything is working now.

我有这些症状;我的Global.asax崩溃了。修复了崩溃,现在一切正常。