In the web.config:
<configuration>
<authentication mode="Windows">
</authentication>
<authorization>
<deny users="?" />
</authorization>
</configuration>
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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0