asp.net-mvc IIS 7 中的 ASP MVC 导致:HTTP 错误 403.14 - 禁止

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

ASP MVC in IIS 7 results in: HTTP Error 403.14 - Forbidden

asp.net-mvciishosting

提问by savvas sopiadis

I'm developing an ASP MVC web project. Now I have a requirement which forces me to deploy to an IIS7 inmiddle of development (to check some features). I'm getting the above mentioned error message whenever I try to type the URL of the web site. (Note: development machine: Vista Home Premium, IIS7)

我正在开发一个 ASP MVC web 项目。现在我有一个要求,它迫使我在开发过程中部署到 IIS7(检查一些功能)。每当我尝试键入网站的 URL 时,都会收到上述错误消息。(注:开发机:Vista Home Premium、IIS7)

What I have done until now:

到目前为止我所做的:

Edited the HOSTS file (C:\WINDOWS\system32\drivers\etc\hosts).

编辑了 HOSTS 文件 (C:\WINDOWS\system32\drivers\etc\hosts)。

Put two domains in it (127.0.0.1 domain1.com & 127.0.0.1 domain2.com).

将两个域放入其中(127.0.0.1 domain1.com 和 127.0.0.1 domain2.com)。

Created a folder c:\websites\dirOfApplication and deployed from within Visual Studio 8 to this folder.

创建了一个文件夹 c:\websites\dirOfApplication 并从 Visual Studio 8 中部署到此文件夹。

In IIS7 created a new site with host name domain1.com and application folder the above.

在 IIS7 中创建了一个新站点,主机名 domain1.com 和应用程序文件夹如上。

Typing the address domain1.com in Web browser results in the above error (HTTP Error 403.14 - Forbidden - The Web server is configured to not list the contents of this directory.)

在 Web 浏览器中键入地址 domain1.com 会导致上述错误(HTTP 错误 403.14 - 禁止 - Web 服务器被配置为不列出此目录的内容。)

I think I'm missing something but don't know what! Tryed to deploy the files System.Web.Mvc, System.Web.Abstraction & System.Web.Routing wit the same outcome. Whenever I try to hit F5 and run the application, it works fine!

我想我错过了一些东西,但不知道是什么!尝试以相同的结果部署文件 System.Web.Mvc、System.Web.Abstraction 和 System.Web.Routing。每当我尝试按 F5 并运行应用程序时,它都可以正常工作!

回答by Cyril Mestrom

Maybe it's useful to someone: After converting my app to MVC 4 with .NET framework 4.5 and installing the framework on my server with IIS 7.0 I encountered the same 'forbidden' error mentioned in the question. I tried all options described above to no avail, when I noticed the

也许它对某人有用:在使用 .NET Framework 4.5 将我的应用程序转换为 MVC 4 并使用 IIS 7.0 在我的服务器上安装框架后,我遇到了问题中提到的相同“禁止”错误。我尝试了上述所有选项都无济于事,当我注意到

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

was missing from my web.config. After adding this, everything worked. Simple, but easy to overlook...

我的 web.config 中丢失了。添加后,一切正常。简单,但容易被忽视......

EDIT:

编辑:

Of course the solution above will work, but it is indeed a waste of resources. I think it is better to add the routing module as pointed out by Chris Herringin the comments.

上面的方案当然可以,但是确实是浪费资源。我认为最好添加Chris Herring在评论中指出的路由模块。

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

回答by Brettski

Answered on SO here, question: 403 - Forbidden on basic MVC 3 deploy on iis7.5

这里回答,问题:403 - 禁止在 iis7.5 上部署基本 MVC 3

Run aspnet_regiis -i. Often I've found you need to do that to get 4.0 apps to work. Open a command prompt as an Administrator(right click the command prompt icon and select Run as Administrator):

运行aspnet_regiis -i。我经常发现您需要这样做才能使 4.0 应用程序正常工作。打开命令提示符Administrator(右键单击命令提示符图标并选择以管理员身份运行):

cd \
cd Windows\Microsoft.NET\Framework\v4.xxx.xxx
aspnet_regiis -i

Once it has installed and registered, make sure you application is using an application pool that is set to .NET 4.0.

安装并注册后,请确保您的应用程序使用设置为 .NET 4.0 的应用程序池。

UPDATE: I just found an issue with this command. Using -i updated all application pools to ASP.NET 4.0.

更新:我刚刚发现这个命令有问题。使用 -i 将所有应用程序池更新为 ASP.NET 4.0。

Using aspnet_regiis -irinstalls the version of ASP.NET but does not change any web applications to this version. You may also want to review the -iru option.

Usingaspnet_regiis -ir会安装 ASP.NET 的版本,但不会将任何 Web 应用程序更改为此版本。您可能还想查看 -iru 选项。

回答by Bogdan Litescu

I too ran into this error. All the configuration and permissions were correct. But I forgot to copy Global.asax to the server, and that's what gave the 403 error.

我也遇到了这个错误。所有的配置和权限都是正确的。但是我忘记将 Global.asax 复制到服务器,这就是 403 错误的原因。

回答by savvas sopiadis

It's because of being too sure about what you (me) are doing!

那是因为太确定你(我)在做什么!

On my machine there is IIS 7 installed but the required ASP.NET component (Control Panel->Programs->Turn On/Off->ASP.NET) was not.

在我的机器上安装了 IIS 7,但没有安装所需的 ASP.NET 组件(控制面板->程序->打开/关闭->ASP.NET)。

So installing this solved the problem

所以安装这个解决了这个问题

回答by Donny V.

I had the same issue. This Microsoft support article fixed it for me.
https://support.microsoft.com/en-us/help/2023146/mvc-2-and-asp.net-4-web-forms-applications-that-use-url-routing-might-return-http-404-errors-when-they-attempt-to-process-extensionless-urls-on-iis-7-and-iis-7.5

我遇到过同样的问题。这篇 Microsoft 支持文章为我修复了它。
https://support.microsoft.com/en-us/help/2023146/mvc-2-and-asp.net-4-web-forms-applications-that-use-url-routing-might-return-http- 404-errors-when-they-attempt-to-process-extensionless-urls-on-iis-7-and-iis-7.5

In the "Turn Windows Features On or Off" dialog box of the Windows Control Panel "Programs and Features" application, perform the following steps:

在 Windows 控制面板“程序和功能”应用程序的“打开或关闭 Windows 功能”对话框中,执行以下步骤:

  1. Navigate to the following node: Internet Information Services --> World Wide Web Services --> Common HTTP Features
  2. Make sure that the "HTTP Error Redirection" option is selected.
  1. 导航到以下节点:Internet Information Services --> World Wide Web Services --> Common HTTP Features
  2. 确保选择了“HTTP 错误重定向”选项。

-or-

-或者-

  1. Navigate to the following node: Internet Information Services --> World Wide Web Services --> Performance Features
  2. Make sure that the "Static Content Compression" option is selected. After either option has been selected, click "OK" to save changes.
  1. 导航到以下节点:Internet Information Services --> World Wide Web Services --> Performance Features
  2. 确保选择了“静态内容压缩”选项。选择任一选项后,单击“确定”以保存更改。

Re-enabling either the HTTP Error Redirection module or the Static Content Compression module ensures that ASP.NET and IIS correctly synchronize HTTP pipeline events. This enables the URL routing module to process extensionsless URLs.

重新启用 HTTP 错误重定向模块或静态内容压缩模块可确保 ASP.NET 和 IIS 正确同步 HTTP 管道事件。这使 URL 路由模块能够处理无扩展名的 URL。

回答by Murat Y?ld?z

Try to apply the following settings shown below:

尝试应用如下所示的设置:

1)Give the necessary permission to the IIS_IUSRSuser on IIS Server(Right click on the web site then Edit Permissions > Security).

1)授予IIS_IUSRS用户必要的权限IIS Server(右键单击网站,然后编辑权限 > 安全)。

enter image description here

在此处输入图片说明

2)If you use .NET Framework 4, be sure that .NET Framework version is v4.0on the Application Poolthat your web site uses.

2)如果您使用.NET Framework 4,请确保 .NET Framework 版本v4.0Application Pool您的网站使用的版本上。

enter image description here

在此处输入图片说明

3)Open Commanp Prompt as administratorand run iisresetcommand in order to restart IIS Server.

3)打开 Command Prompt asadministrator并运行iisreset命令以重新启动IIS Server

Hope this helps...

希望这可以帮助...

回答by Stefan Michev

In my case following approach helped me out:

在我的情况下,以下方法帮助了我:

  1. aspnet_regiis -iin Windows\Microsoft.Net\Framework

  2. Adding modules to system.webServer

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        ...
    </system.webServer>
    
  1. aspnet_regiis -iWindows\Microsoft.Net\Framework

  2. 将模块添加到 system.webServer

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

回答by David Christiansen

Please also check, if you are running x64, that you have enabled 32-bit applications in the app pool settings

如果您运行的是 x64,还请检查您是否在应用程序池设置中启用了 32 位应用程序

enter image description here

在此处输入图片说明

回答by JTTx

On the Uncheck "Precompile During Publishing"- I was getting the 403.14error on a web service I had just written in VS2015 so I rewrote it in VS2013 and was getting the same error. In both cases I had "Precompile During Publishing" on. I unchecked it but was still getting the error. In my case I also had "Delete all existing files prior to publish" but was not deleting everything from the target directory on the server before copying the new published files there. If you don't do that - a "PrecompiledApp.config" file is left behind which causes the problem. Once I deleted that file I was golden on both the VS2013 and VS2015 versions of my web service.

取消选中“发布期间预编译”时- 我刚刚在 VS2015 中编写的 Web 服务出现403.14错误,因此我在 VS2013 中重新编写它并得到相同的错误。在这两种情况下,我都启用了“发布期间预编译”。我取消选中它,但仍然收到错误。在我的情况下,我也有“在发布之前删除所有现有文件”,但在将新发布的文件复制到那里之前并没有从服务器上的目标目录中删除所有内容。如果您不这样做 -会留下“ PrecompiledApp.config”文件,这会导致问题。删除该文件后,我在 VS2013 和 VS2015 版本的 Web 服务上都表现出色。

回答by codeMonkey

I tried everything here; nothing worked. Problem was in my Web.configfile, somehow dependent assembly binding got changed from minimum 1to minimum 0.

我在这里尝试了一切;没有任何效果。问题出在我的Web.config文件中,以某种方式依赖程序集绑定从 minimum 更改1为 minimum 0

<!-- was -->
<runtime>
    <assemblyBinding>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" />
                <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />


<!-- should have been -->
                <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />