Question

Is there any event in global.asax that is fired just once after the user is authenticated or authorized? Session start fires whenever user enter in application no matter he's authorized or not.

Was it helpful?

Solution

Add this event in global.asax page ,for check current user if logedin and store the user details in httpconext.current.user .

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
    if (HttpContext.Current.User != null)
    {
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            if (HttpContext.Current.User.Identity is FormsIdentity)
            {
                FormsIdentity id =
                    (FormsIdentity)HttpContext.Current.User.Identity;
                FormsAuthenticationTicket ticket = id.Ticket;

                // Get the stored user-data, in this case, our roles
                string userData = ticket.UserData;
                string[] roles = userData.Split(',');
                HttpContext.Current.User = new GenericPrincipal(id, roles);
            }
        }
    }
} 

OTHER TIPS

The AuthenticateRequest fires on every request allowing you to prepare the HttpContext for the execution of the request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top