C# 设置 MVC 应用程序后访问被拒绝错误

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

Access Denied error after setting up MVC application

c#asp.net-mvc-4

提问by Nick Ky

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. Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET > Version:4.0.30319.18010

访问被拒绝。

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

错误消息 401.2。:未经授权:由于服务器配置,登录失败。根据您提供的凭据和 Web 服务器上启用的身份验证方法,验证您是否有权查看此目录或页面。联系 Web 服务器的管理员以获得更多帮助。版本信息:Microsoft .NET Framework 版本:4.0.30319;ASP.NET > 版本:4.0.30319.18010

I followed the simple tutorial from here, ran the application and received this message.

我遵循了这里的简单教程,运行了应用程序并收到了这条消息。

回答by viperguynaz

Check your project properties and ensure that Anonymous Authentication = Enabled. If you have <authentication mode="Windows" />in your web.config, you will also need to set Windows Authentication = Enabledfor the project (click the project in Solution Explorer):

检查您的项目属性并确保 Anonymous Authentication = Enabled。如果您<authentication mode="Windows" />的 web.config 中有,您还需要为项目设置 Windows Authentication = Enabled(单击解决方案资源管理器中的项目):

Properties

特性

The effect this has is to change the project file (.csproj) from saying:

这样做的效果是将项目文件 (.csproj) 更改为:

<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />

To:

到:

<IISExpressAnonymousAuthentication>enabled</IISExpressAnonymousAuthentication>
<IISExpressWindowsAuthentication>enabled</IISExpressWindowsAuthentication>

So you can also do this by hand, or fix it permanently by modifying the intranet project template.

所以你也可以手动进行,或者通过修改内网项目模板永久修复。

回答by Cyrus Downey

So I just wanted to chime in on something that worked for me. I created a new "ASP.Net MCV 4 Web application" and used the "Intranet Application" project template. I had to enable "Windows Authentication". I assume this is because I chose the intranetapplication template versus the internetapplication template.

所以我只是想谈谈对我有用的东西。我创建了一个新的“ASP.Net MCV 4 Web 应用程序”并使用了“Intranet 应用程序”项目模板。我必须启用“Windows 身份验证”。我认为这是因为我选择了Intranet应用程序模板而不是Internet应用程序模板。

回答by Moji

Basically first allow users or rolse access

基本上首先允许用户或角色访问

Default web.config denies access

默认 web.config 拒绝访问

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

so make sure you allow yourself

所以请确保你允许自己

<authorization>
  <allow users="domain\User" />
  <deny users="?" />
</authorization>