Global.asax Event: Application_OnPostAuthenticateRequest

Posted by Hemant Kothiyal on Stack Overflow See other posts from Stack Overflow or by Hemant Kothiyal
Published on 2009-07-18T11:04:50Z Indexed on 2010/03/21 23:01 UTC
Read the original article Hit count: 375

Filed under:

Hi, I am using Application_OnPostAuthenticateRequest event in global.asax to get

  1. roles and permissions of authenticated user also i have made my custom principal class to get user detail and roles and permission.

  2. To get some information which remain same for that user.

following are the code

void Application_OnPostAuthenticateRequest(object sender, EventArgs e) {

    // Get a reference to the current User

    IPrincipal objIPrincipal = HttpContext.Current.User;

    // If we are dealing with an authenticated forms authentication request

    if ((objIPrincipal.Identity.IsAuthenticated) && (objIPrincipal.Identity.AuthenticationType == "Forms"))
    {
        CustomPrincipal objCustomPrincipal = new CustomPrincipal();
        objCustomPrincipal = objCustomPrincipal.GetCustomPrincipalObject(objIPrincipal.Identity.Name);
        HttpContext.Current.User = objCustomPrincipal;
        CustomIdentity ci = (CustomIdentity)objCustomPrincipal.Identity;
        HttpContext.Current.Cache["CountryID"] = FatchMasterInfo.GetCountryID(ci.CultureId);
        HttpContext.Current.Cache["WeatherLocationID"] = FatchMasterInfo.GetWeatherLocationId(ci.UserId);
        Thread.CurrentPrincipal = objCustomPrincipal;
    }
}

My question is as following

  1. This event fires every time for every request. Hence for each request the code execute?
  2. My approach is right or not?
  3. Is it right to add HttpContext.Current.Cache in this event or we should move it on session start

© Stack Overflow or respective owner

Related posts about asp.net-2.0