Pergunta

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.

Foi útil?

Solução

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);
            }
        }
    }
} 

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top