Global.asax中的ASP.NET会话
发布时间:2020-12-16 04:36:09 所属栏目:asp.Net 来源:网络整理
导读:Global.asax中的Application_AuthenticateRequest方法中的会话始终为null.我已经尝试过: this.Session,HttpContext.Current.Session 总是空的. protected void Application_AuthenticateRequest() { string userRole = string.Empty; if (Request.IsAuthent
Global.asax中的Application_AuthenticateRequest方法中的会话始终为null.我已经尝试过:
this.Session,HttpContext.Current.Session 总是空的. 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}); } } 我也尝试使用Cache,但它不起作用,因为我需要每个用户的唯一信息. 如何在Global.asax中使用Session?HttpApplication Application属性是否对每个用户都是唯一的? 解决方法
您现在无法在请求生命周期中使用Session,它不可用/已填充,如果您想使用它,您需要在生命周期的后期移动到事件,例如
PostAcquireRequestState .
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – 如何正确覆盖EF 4.1中的SaveChanges函数
- asp.net – 从web.config中膨胀时,SmtpClient不会进行身份验
- 什么是ASP.NET?
- asp-classic – 如何在asp经典中触发异步调用并忽略响应?
- 在ASP.NET中使用新的会话ID打开一个新的浏览器窗口
- asp.net – 在向下滚动页面后,对于webkit浏览器,AutoComple
- asp.net-identity – IIdentity.Name与IIdentity.GetUserNa
- asp.net – 为什么IIS中的Windows /集成身份验证不会将用户
- .net – ServiceHost和WebServiceHost有什么区别?
- 我可以使用ASP Classic构建REST应用程序吗?
推荐文章
站长推荐
- asp.net – 如何在WCF中使用SOAP :: Lite?
- asp.net-mvc – 在asp.net MVC中排序表
- ASP.NET异步方法问题
- asp.net-mvc – 从MVC5框架OAuth/OWin身份提供程
- (推荐)第15章 扩展ASP.NET MVC (IModelBinder、
- asp.net-mvc-4 – 使用@ Url.Content(“?”)有什
- asp.net-mvc-4 – 附加到HTTP响应的CORS标头未发
- 嵌套字典到嵌套转发器asp.net c#
- asp.net-mvc – 清除模型后为什么文本框不清除
- asp.net-mvc – 如何从MVC控制器返回Json对象到视
热点阅读