views:

169

answers:

1

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

+2  A: 

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()
    {

    }
}
korchev