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)
{
IPrincipal objIPrincipal = HttpContext.Current.User;
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.