Global.asax event: Application_OnPostAuthenticateRequest

I use event Application_OnPostAuthenticateRequestin global.asaxto get

a) Roles and permissions of the authenticated user, I also made my custom main class to get user details, roles and permissions.

b) To obtain information that remains the same for this user.

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 this:

  • This event fires every time for each request. Therefore, is the code executed for each request?
  • Is my approach right or wrong?
  • Is it correct to add HttpContext.Current.Cache to this event or should we transfer it to Session_Start.
+3
1
  • , .
  • , .
  • , HttpCurrent.Current.Cache , , . HttpContext.Current.Session, .
+4

Source: https://habr.com/ru/post/1712928/


All Articles