【问题标题】:Windows Authentication succeeds but IsAuthenticated == falseWindows 身份验证成功但 IsAuthenticated == false
【发布时间】:2010-06-29 15:22:18
【问题描述】:

环境是 IIS 7 集成管道,ASP.NET 4.0。我有一个配置为没有匿名身份验证和 Windows 身份验证的 .aspx 页面:

  <location path="auth/windows">
    <system.webServer>
      <security>
        <authentication>
          <anonymousAuthentication enabled="false" />
          <windowsAuthentication enabled="true" />
        </authentication>
      </security>
    </system.webServer>
  </location>

当我请求页面时,会发生正常的 Windows auth (NTLM/Negotiate) 质询响应,并最终返回页面。

我有一个处理 PostAuthorize 事件的 HttpModule。正如预期的那样,只有在质询-响应身份验证成功并且对页面的访问权限已被授权时才会引发此事件。

但是,Request.IsAuthenticated 属性为 false;和 HttpContext.Current.User.Identity 反映未经身份验证的用户(.Name 返回空字符串)。有趣的是,Request.ServerVariables["LOGON_USER"] 确实返回了经过身份验证的 Windows 用户的值。

我原以为一旦用户通过身份验证(就此而言,并获得授权),请求将反映已通过身份验证;并且请求的用户/身份已经正确设置。

对为什么不是这种情况有什么想法吗?

谢谢,

唐尼

【问题讨论】:

  • 启用模拟,看看你会得到什么。

标签: asp.net authentication iis-7


【解决方案1】:

事实证明,当您在 Web.config 中启用 Forms 身份验证时,Windows 身份验证的本机处理工作。但是 Windows 身份验证的托管部分 - 将经过身份验证的 Windows 用户与代表该用户的 IIdentity 派生对象相关联 - 只有在 Web.config 中启用 Windows 身份验证时才会发生。看起来我将不得不依赖 Request.ServerVariables["LOGON_USER"] 值。

【讨论】:

    【解决方案2】:

    IIS 中启用了windows 身份验证,并且在我的web.config 文件中将身份验证模式设置为windows。

     <authentication mode="Windows">     
        </authentication>
    

    我的网站要求提供凭据,并且工作正常。但是当使用

    检查时
    HttpContext.User.Identity.Name
    

    为空字符串 或者 HttpContext.User.Identity.IsAuthenticated 是假的;

    我使用 Request.ServerVariables["LOGON_USER"].Tostring(); 获取登录用户凭据。

    它对我有用,感谢您发布soccerdad。

    【讨论】:

    • 欢迎来到stackoverflow Venu,当您的声誉增长时,您将能够发布cmets。否则答案只是为了回答问题。干杯!
    • 这不是答案,而是对soccerdad 答案的评论。
    猜你喜欢
    • 2014-02-17
    • 1970-01-01
    • 2018-09-22
    • 2022-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多