调试 ASP.NET MVC 时,IIS Express 出现访问被拒绝错误

发布于 2024-12-29 18:33:18 字数 325 浏览 1 评论 0原文

我创建了一个 ASP.NET MVC 3 项目,并在开发时使用 IIS Express 作为 Web 服务器。当我尝试调试时,收到以下错误消息。

如何解决这个问题?

“/”应用程序中的服务器错误。

访问被拒绝。 描述:访问服务此请求所需的资源时发生错误。服务器可能未配置为访问所请求的 URL。

错误消息 401.2.:未经授权:由于服务器配置导致登录失败。根据您提供的凭据以及 Web 服务器上启用的身份验证方法,验证您是否有权查看此目录或页面。请联系 Web 服务器的管理员以获得更多帮助。

I have created an ASP.NET MVC 3 project, and am using IIS Express as the web server when developing. When I try to debug, I get the error message below.

How can this be solved?

Server Error in '/' Application.

Access is denied.
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

差↓一点笑了 2025-01-05 18:33:18

如果您使用的是 Visual Studio,还可以在解决方案资源管理器中左键单击该项目,然后将Windows 身份验证属性更改为已启用 属性窗口。

If you are using Visual Studio, you can also left-click on the project in Solution Explorer and change the Windows Authentication property to Enabled in the Properties window.

失退 2025-01-05 18:33:18

造成此问题的原因是 IIS Express 不允许 WindowsAuthentication。可以通过

<windowsAuthentication enabled="true">

在位于 C:\Users[用户名]\Documents\IISExpress\config 的 applicationhost.config 文件中进行设置来启用此功能。

The cause if had for this problem was IIS Express not allowing WindowsAuthentication. This can be enabled by setting

<windowsAuthentication enabled="true">

in the applicationhost.config file located at C:\Users[username]\Documents\IISExpress\config.

爱本泡沫多脆弱 2025-01-05 18:33:18

我使用了杰森的答案,但想澄清如何进入属性。

  1. 在解决方案资源管理器中选择项目

在此处输入图像描述

  1. F4 获取属性(与右键单击不同)
    属性)
  2. Windows身份验证更改为启用

在此处输入图像描述

I used Jason's answer but wanted to clarify how to get in to properties.

  1. Select project in Solution Explorer

enter image description here

  1. F4 to get to properties (different than the right click
    properties)
  2. Change Windows Authentication to Enabled

enter image description here

月隐月明月朦胧 2025-01-05 18:33:18

在 IIS Express 上托管:
1. 在解决方案资源管理器中单击您的项目以选择该项目。
2. 如果“属性”窗格未打开,请将其打开 (F4)。
3. 在项目的“属性”窗格中:
a) 将“匿名身份验证”设置为“禁用”。
b) 将“Windows 身份验证”设置为“启用”。

Hosting on IIS Express:
1. Click on your project in the Solution Explorer to select the project.
2. If the Properties pane is not open, open it (F4).
3. In the Properties pane for your project:
a) Set "Anonymous Authentication" to "Disabled".
b) Set "Windows Authentication" to "Enabled".

坏尐絯 2025-01-05 18:33:18

就我而言,我必须打开该文件:

C:\...\Documents\IISExpress\config\applicationhost.config

我在文件中包含以下内容:

  <authentication>
  <anonymousAuthentication enabled="true" User="" />

我刚刚删除了 User="" 部分。我真的不知道这个东西是怎么到那里的...:)

注意:确保在 applicationhost.config 末尾有类似的东西:

   .
   .
   .
   <location path="MyCompany.MyProjectName.Web">
        <system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication enabled="true" />
                    <windowsAuthentication enabled="false" />
                </authentication>
            </security>
        </system.webServer>
    </location>
</configuration>

您可能还想看看这里: https://stackoverflow.com/a/10041779/114029

现在我可以按预期访问登录页面。

In my case I had to open the file:

C:\...\Documents\IISExpress\config\applicationhost.config

I had this inside the file:

  <authentication>
  <anonymousAuthentication enabled="true" User="" />

I just removed the User="" part. I really don't know how this thing got there... :)

Note: Make sure you have something like this in the end of applicationhost.config:

   .
   .
   .
   <location path="MyCompany.MyProjectName.Web">
        <system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication enabled="true" />
                    <windowsAuthentication enabled="false" />
                </authentication>
            </security>
        </system.webServer>
    </location>
</configuration>

You may also want to take a look here: https://stackoverflow.com/a/10041779/114029

Now I can access the login page as expected.

绅士风度i 2025-01-05 18:33:18

就我而言,之前从 VS 运行的应用程序保留了该 URL。我可以通过在控制台中运行来看到这一点:

netsh http show urlacl

要删除此预订,我在高架控制台中运行了此操作:

netsh http delete urlacl http://127.0.0.1:10002/

我找到了这些步骤这里解决了我的问题。

我用的是VS2013

In my case a previous run of my app from VS reserved the URL. I could see this by running in a console:

netsh http show urlacl

to delete this reservation i ran this in an elevated console:

netsh http delete urlacl http://127.0.0.1:10002/

I found these steps here solved my problem.

I'm using VS2013

秋凉 2025-01-05 18:33:18

我必须在管理模式下运行 Visual Studio 才能消除此错误。

I had to run Visual Studio in Administrative Mode to get rid of this error.

花间憩 2025-01-05 18:33:18

我也遇到了同样的问题,最后我可以克服它。

解决方案资源管理器右键单击项目属性 > → Web 选项卡项目 URL

我选择了另一个端口号,并且一切都变得美好了!

I had also the same problem and finally I could overcame it.

Solution ExplorerRight click on projectPropertiesWeb tabProject Url

I have chosen another port number, and every things became fine!

遗弃M 2025-01-05 18:33:18

我打开 web.config 文件,找到并删除了此部分:

<authorization>
  <deny users="?" />
</authorization>

我的网站出现了,但身份验证存在问题。

I opened my web.config file, and found and removed this section:

<authorization>
  <deny users="?" />
</authorization>

and my site came up, but there are issuues with the authentication..

奈何桥上唱咆哮 2025-01-05 18:33:18

以上这些都不适合我。在今天之前这对我来说一直有效。然后我意识到我一直在我的笔记本电脑上创建托管连接,并与我的无线网络连接共享互联网连接。

要解决我的问题:

转到“控制面板”>“网络和互联网>网络连接

右键单击​​您可能拥有的任何辅助无线网络连接(我的连接名为无线网络连接 2),然后单击“属性”。

转到顶部的“共享”选项卡。

取消选中“允许其他网络用户通过此计算机的 Internet 连接进行连接”复选框。

点击确定>然后申请。

希望这有帮助!

None of the above had worked for me. This had been working for me prior to today. I then realized I had been working with creating a hosted connection on my laptop and had Shared an internet connection with my Wireless Network Connection.

To fix my issue:

Go to Control Panel > Network and Internet > Network Connections

Right click on any secondary Wireless Network Connection you may have (mine was named Wireless Network Connection 2) and click 'Properties'.

Go to the 'Sharing' tab at the top.

Uncheck the box that states 'Allow other network users to connect through this computer's Internet connection'.

Hit OK > then Apply.

Hope this helps!

趁年轻赶紧闹 2025-01-05 18:33:18

我刚刚在 IIS EXPRESS 中修复了这个确切的问题,通过将应用程序主机 .config 编辑到下面特定的位置部分来修复它。我已经在 Visual Studio 2012 中设置了 Windows 身份验证,但是当我进入 XML 时,它看起来像这样。

需要添加 windows auth 标签,如下所示。

<windowsAuthentication enabled="true" />

<location path="MyApplicationbeingDebugged">
        ``<system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication enabled="false" />
                    <!-- INSERT TAG HERE --> 
                </authentication>
            </security>
        </system.webServer>
</location>

I just fixed this exact problem in IIS EXPRESS fixed it by editing the application host .config to the location section specific to the below. I had set Windows Authentication in Visual Studio 2012 but when I went into the XML it looked like this.

the windows auth tag needed to be added below as shown.

<windowsAuthentication enabled="true" />

<location path="MyApplicationbeingDebugged">
        ``<system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication enabled="false" />
                    <!-- INSERT TAG HERE --> 
                </authentication>
            </security>
        </system.webServer>
</location>
笑看君怀她人 2025-01-05 18:33:18

我一直在努力解决这个问题,尝试使用提供商托管的 SharePoint 创建一个简单的应用程序。

浏览完 applicationhost.config 后,在 部分中,basicAuthentication 设置为 false。我将其更改为 true 以通过我的场景中的 401.2。还有很多其他链接介绍如何查找 IIS Express 的 applicationhost.config。

I've been struggling with this problem trying to create a simple App for SharePoint using Provider Hosted.

After going through the applicationhost.config, in the section, basicAuthentication was set to false. I changed it to true to get past the 401.2 in my scenario. There are plenty of other links of how to find the applicationhost.config for IIS Express.

终陌 2025-01-05 18:33:18

我在任何地方都没有看到这个“完整”的答案;我发布此文章后刚刚看到有关更改端口号的文章,所以嗯。

确保在 Visual Studio 的项目属性中,项目 url 未分配给 IIS 中用于任何站点绑定的相同 url 或端口。

我正在为此查找“原因”,但我的假设是 IIS 和 Visual Studio 的 IIS Express 在创建虚拟目录时使用相同的目录,而 Visual Studio 只能创建新的虚拟目录而无法修改IIS 在将其绑定应用到站点时创建的任何内容。

请随时纠正我的原因。

I didn't see this "complete" answer anywhere; I just saw the one about changing port numbers after I posted this, so meh.

Make sure that in your project properties in visual studio that project url is not assigned to the same url or port that is being used in IIS for any site bindings.

I'm looking up the "why" for this, but my assumption off the top of my head is that both IIS and Visual Studio's IIS express use the same directory when creating virtual directories and Visual Studio can only create new virtual directories and cannot modify any that IIS has created when it applies it's bindings to the site.

feel free to correct me on the why.

黯然 2025-01-05 18:33:18

我们的错误页面位于登录页面后面,但登录页面的其中一个控件出现错误,从而造成无限循环。

我们从有问题的页面中删除了所有控件,然后将它们一一添加回来,直到找到并修复了正确的控件。

Our error page was behind the login page, but the login page had an error in one of the controls, which creates an infinite loop.

We removed all the controls from the offending page, and added them back one by one until the correct control was located and fixed.

余生共白头 2025-01-05 18:33:18

就我而言(ASP.NET MVC 4 应用程序),Global.asax 文件丢失。它出现在解决方案资源管理器中并带有感叹号。我更换了它,错误就消失了。

In my case (ASP.NET MVC 4 application), the Global.asax file was missing. It was appearing in Solution explorer with an exclamation mark. I replaced it and the error went away.

抱猫软卧 2025-01-05 18:33:18

我在我一直从事的 1 个项目中遇到了几乎相同的错误。其他所有项目都还可以。
就我而言,这是因为我的所有项目都位于网络驱动器上。

不知何故,我的该项目的“以前的项目”快捷方式条目已更改/覆盖为使用映射驱动器。即使映射的驱动器有效并且工作,我也会收到此错误。

访问被拒绝。
描述:访问服务此请求所需的资源时发生错误。您可能无权查看所请求的资源。

错误消息401.3:您没有查看此目录的权限
或使用您提供的凭据进行寻呼(由于访问被拒绝
访问控制列表)。请求Web服务器的管理员给你
访问“Y:...”

关闭项目并使用 UNC 路径“\\networkdevice\path\project”..
启动VS项目,一切正常。
愚蠢的小错误,但也许对某人有帮助。

I had almost the same error on 1 project I have been working on. All others projects were still OK.
In my case , it was because all my projects are located on a network drive.

Somehow my 'previous projects' shortcut entry for this project was changed\ overwritten to using a mapped drive. Even though the mapped drive was valid and working, I would get this error.

Access is denied.
Description: An error occurred while accessing the resources required to serve this request. You might not have permission to view the requested resources.

Error message 401.3: You do not have permission to view this directory
or page using the credentials you supplied (access denied due to
Access Control Lists). Ask the Web server's administrator to give you
access to 'Y:...."

Close the project and use the UNC Path "\\networkdevice\path\project" ..
to start the VS project and it all works fine.
Silly little error, but maybe helps someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文