質問

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