【问题标题】:Keeps being prompted for credentials不断提示输入凭据
【发布时间】:2018-06-23 11:27:26
【问题描述】:

到目前为止我做了什么:

  1. 使用此 web.config 创建网站(这只是设置部分,而不是整个文件 :))

    <appSettings>
    <add key="webpages:Version" value="3.0.0.0"/>
    <add key="webpages:Enabled" value="false"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
    <add key="autoFormsAuthentication" value="false"/>
    <add key="enableSimpleMembership" value="false"/>
    </appSettings>
    <system.web>
    <compilation debug="true" targetFramework="4.6.2"/>
    <httpRuntime targetFramework="4.6.2"/>
    <authentication mode="Windows"></authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
    </system.web>
    
  2. 创建了一个控制器:

    [Authorize(Users = @"myPcName\myUserName,skynet\Simple")]
    public class AuthenController : Controller
    {
        [Authorize(Users = @"myPcName\myUserName")]
        public ActionResult ForAdministrator()
        {
            return View();
        }
        [Authorize(Users = @"myPcName\Simple")]
        public ActionResult ForUser()
        {
            return View();
        }
    }
    

我通过 cmd -> whoami 获得了我的凭据

  1. 我以发布模式将我的 mvc 站点发布到 c:\inetpub\wwwroot\backoffice
  2. 在 IIS 中:

  3. 我什至在 Intranet 选项中将我的站点添加到本地 Intranet,并且:

它只是一次又一次地提示我输入凭据:

【问题讨论】:

  • 因为您在安全设置中将用户身份验证指定为提示输入用户名和密码
  • 如果你只使用[Authorize],它是否有效?可能是您不需要指定 PC 名称并且它不起作用,因为它无法识别用户名
  • 嗨@Kaj,即使我将互联网选项设置为“匿名登录”,它仍然无法正常工作
  • @TAHASULTANTEMURI,不是。我尝试了那里的建议,但没有奏效。

标签: c# asp.net-mvc authentication windows-authentication


【解决方案1】:

只是为了帮助遇到这个问题的人: 我解决问题的方法是: 单击VS中的项目。 按 F4 进入属性 将“匿名身份验证”设置为禁用

在 web.config 中:

<authentication mode="Windows"></authentication>
<authorization>
  <allow users="*" />
</authorization>

在你的控制器中:

    [Authorize(Users = @"pcName\user")]
    public ActionResult ForAdministrator()
    {
        return View();
    }

    // Authorization with windows authentication (user)
    [Authorize(Users = @"pcName\user")]
    public ActionResult ForUser()
    {
        return View();
    }

其中 pcName 是您的电脑的名称(不是 WORKGROUP!)

通过这种方式,您可以控制谁被允许(因为匿名身份验证被禁用)。

希望它可以帮助某人。 罗特姆

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多