Global.asax 中的Application_AuthenticateRequest方法中的会话始终为null.我已经尝试过:
this.Session,HttpContext.Current.Session
Run Code Online (Sandbox Code Playgroud)
总是空的.
protected void Application_AuthenticateRequest()
{
string userRole = string.Empty;
if (Request.IsAuthenticated)
{
if (this.Session["UserRole"] == null)
{
InsertSessionValue();
}
userRole =Session["UserRole"].ToString();
HttpContext.Current.User = new GenericPrincipal(User.Identity, new string[] {userRole});
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试使用Cache,但它不起作用,因为我需要每个用户的唯一信息.
如何在Global.asax中使用Session?HttpApplication Application属性是否对每个用户都是唯一的?
| 归档时间: |
|
| 查看次数: |
3146 次 |
| 最近记录: |