HttpContext.Current.User是Windows身份验证(集成管道)下空 [英] HttpContext.Current.User is null under windows authentication (integrated pipeline)
问题描述
在web.config中:
In the web.config:
<configuration>
<authentication mode="Windows">
</authentication>
<authorization>
<deny users="?" />
</authorization>
</configuration>
在Global.asax中
in global.asax
protected void Application_AuthenticateRequest(object sender, EventArgs args)
{
tracker.LogRequest(HttpContext.Current.User, DateTime.Now)
///THIS IS ALWAYS NULL!!!
}
我只是真的被这个迷惑,任何想法?
I am just really confused by this, any ideas?
推荐答案
我觉得这是侦听的错误事件的征兆。你应该听<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.httpapplication.postauthenticaterequest.aspx\"相对=nofollow> Application.PostAuthenticateRequest 。
I think this is a symptom of listening on the wrong event. You should probably listen for Application.PostAuthenticateRequest.
使用项目运行code的样片我有一个验证我对本地域中的Active Directory问,如果用户对象是什么:
Running a sample piece of code using a project I have that authenticates against my local domain's Active Directory to ask if the User object is nothing:
code
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
Debug.WriteLine("Authenticate Request: " & (HttpContext.Current.User Is Nothing))
End Sub
Sub Application_PostAuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
Debug.WriteLine("Post-authenticate Request: " & (HttpContext.Current.User Is Nothing))
End Sub
输出
验证请求:真
后进行身份验证请求:假
Post-authenticate Request: False
继 PostAuthenticateRequest
事件中, HttpContext.Current.User.Identity
属性的 System.Security.Principal.GenericIdentity
获取身份认证的请求。
Following the PostAuthenticateRequest
event, the HttpContext.Current.User.Identity
property is an instance of System.Security.Principal.GenericIdentity
for unauthenticated requests.
这篇关于HttpContext.Current.User是Windows身份验证(集成管道)下空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!