HttpContext.Current.User is null under windows authentication (integrated pipeline)

前端 未结 1 1660
旧时难觅i
旧时难觅i 2021-01-07 07:09

In the web.config:


    
    
    
      

        
相关标签:
1条回答
  • 2021-01-07 08:02

    I think this is a symptom of listening on the wrong event. You should probably listen for Application.PostAuthenticateRequest.

    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
    

    Output

    Authenticate Request: True

    Post-authenticate Request: False

    Following the PostAuthenticateRequest event, the HttpContext.Current.User.Identity property is an instance of System.Security.Principal.GenericIdentity for unauthenticated requests.

    0 讨论(0)
提交回复
热议问题