Global.asax Event: Application_OnPostAuthenticateRequest
- by Hemant Kothiyal
Hi, I am using Application_OnPostAuthenticateRequest event in global.asax to get
roles and permissions of authenticated user also i have made my custom principal class to get user detail and roles and permission.
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
This event fires every time for every request. Hence for each request the code execute?
My approach is right or not?
Is it right to add HttpContext.Current.Cache in this event or we should move it on session start