我在用Application_OnPostAuthenticateRequest
事件在global.asax
to get
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
- 是的,每个请求都会触发此事件
- 是的,您可以使用此事件来获取经过身份验证的用户的信息
- No, 不要使用
HttpCurrent.Current.Cache
存储用户特定信息,因为缓存对所有用户来说都是通用的,并且您会遇到冲突。使用HttpContext.Current.Session
相反,因为这将特定于用户。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)