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