Windows身份验证成功但IsAuthenticated == false

4

环境是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身份验证(NTLM / Negotiate)挑战响应,最终返回该页面。
我有一个HttpModule,在其中处理PostAuthorize事件。如预期,此事件仅在挑战 - 响应身份验证成功并授权访问页面后才会引发。
但是,Request.IsAuthenticated属性为false;而HttpContext.Current.User.Identity反映未经身份验证的用户(.Name返回空字符串)。有趣的是,Request.ServerVariables ["LOGON_USER"]确实返回已认证的Windows用户的值。
我本以为一旦用户得到身份验证(也包括授权),请求就会反映已经过身份验证;请求的User / Identity将被正确设置。
你对为什么出现这种情况有什么想法吗?
谢谢,
唐尼

启用模拟并查看结果。 - Tim Coker
2个回答

3

原来,在Web.config启用Forms身份验证时,Windows身份验证的本地处理方式是有效的。但是,将已经通过Windows身份验证的用户与代表该用户的IIdentity派生对象相关联的托管部分仅在Web.config启用Windows身份验证时发生。看起来我必须依靠Request.ServerVariables["LOGON_USER"]值。


2

我的web.config文件中启用了Windows认证,并将认证模式设置为Windows。

IIS中。
 <authentication mode="Windows">     
    </authentication>

我的网站要求输入凭据,目前运行良好。但是当使用

进行检查时出现问题。

HttpContext.User.Identity.Name

字符串为空

或者 HttpContext.User.Identity.IsAuthenticated 为假;

我使用了 Request.ServerVariables["LOGON_USER"].Tostring(); 来获取已登录用户的凭证。

这对我有用,感谢 soccerdad 的发布。


欢迎来到stackoverflow Venu,当您的声望增长时,您将能够发布评论。否则,答案只是为了回答问题。干杯! - Sergio
4
这不是答案,而是对足球爸爸回答的评论。 - Patrick Hofman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接