我在global.asax中使用Application_OnPostAuthenticateRequest事件获取
a)身份验证用户的角色和权限我也创建了自定义主体类,以获取用户详细信息以及角色和权限.
b)获得一些对该用户相同的信息.
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;
}
}
我的问题如下:
>对于每个请求,每次都会触发此事件.因此对于每个请求代码执行?
>我的方法正确与否?
>在此事件中添加HttpContext.Current.Cache是??否正确,否则我们应该将其移至Session_Start