Global.asax中的ASP.NET会话
发布时间:2020-05-24 09:48:18 所属栏目:asp.Net 来源:互联网
导读:Global.asax中的Application_AuthenticateRequest方法中的会话始终为null.我已经尝试过: this.Session,HttpContext.Current.Session 总是空的. protected void Application_AuthenticateRequest() { string userRole = string
|
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请求中)
- 我应该把我的日志文件放在哪里用于asp.net应用程序?
- asp.net – 一些黑客可以从用户窃取cookie,并在网站上使用该
- asp.net-mvc – VS2013不编译ASP.NET MVC5视图
- ASP.NET 2.0或3.5?
- asp.net – 数据库加密或应用程序级加密?
- asp.net-mvc – 如何覆盖Orchard CMS中导航区域的渲染?
- 服务层和ASP.NET MVC的目的2
- asp.net-mvc – ASP.NET MVC – Elmah不工作,返回404页面为
- asp.net-mvc-2 – 如何设置RadioButtonFor()在ASp.net MVC
推荐文章
站长推荐
- asp.net – 使用OAuth在Web API中进行身份验证
- asp.net-mvc – ASP.Net MVC:发送JSON到控制器
- 来自UserControl的ASP.NET AJAX页面方法
- asp.net-mvc-4 – 多个单选按钮组在MVC 4剃刀
- asp.net-mvc – 在ASP.NEt MVC 3中传递Html.Begi
- asp.net-mvc – ASP.Net MVC中的自我AJAX更新部分
- ASP.NET自带对象JSON字符串与实体类的转换
- asp.net-mvc – ActionLink MVC中的图像按钮
- .NET牛人应该知道些什么,我的回答
- ado.net – ASP.NET:如何从web.config Connecti
热点阅读
