Вопрос

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.

Это было полезно?

Решение

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

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top