Jon Erickson
Jon Erickson

Reputation: 114976

When Is HttpContext.User initialized?

When is the earliest point in which I can access HttpContext.User?

Upvotes: 4

Views: 1193

Answers (1)

Atanas Korchev
Atanas Korchev

Reputation: 30671

You could use the AuthenticateRequest event of the HttpApplication. Here is some sample code:

public class MyHttpModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.AuthenticateRequest += context_AuthenticateRequest;
    }

    void context_AuthenticateRequest(object sender, EventArgs e)
    {
        var application = (HttpApplication) sender;
        var name = application.Context.User.Identity.Name;
    }

    public void Dispose()
    {

    }
}

Upvotes: 4

Related Questions