asp.net – 尽管设置了FormsAuthenticationTicket的UserData属性
发布时间:2020-12-15 22:16:31 所属栏目:asp.Net 来源:网络整理
导读:出于某种原因,我的身份验证cookie的UserData属性为空.这是代码: var authCookie = FormsAuthentication.GetAuthCookie(userName,rememberUser.Checked);// Get the FormsAuthenticationTicket out of the encrypted cookievar ticket = FormsAuthentication
出于某种原因,我的身份验证cookie的UserData属性为空.这是代码:
var authCookie = FormsAuthentication.GetAuthCookie(userName,rememberUser.Checked); // Get the FormsAuthenticationTicket out of the encrypted cookie var ticket = FormsAuthentication.Decrypt(authCookie.Value); // Create a new FormsAuthenticationTicket that includes our custom User Data var newTicket = new FormsAuthenticationTicket(ticket.Version,ticket.Name,ticket.IssueDate,ticket.Expiration,ticket.IsPersistent,"userData"); // Update the authCookie's Value to use the encrypted version of newTicket authCookie.Value = FormsAuthentication.Encrypt(newTicket); // Manually add the authCookie to the Cookies collection Response.Cookies.Add(authCookie); FormsAuthentication.RedirectFromLoginPage(userName,rememberUser.Checked); 以下是我尝试访问它的方法: if (HttpContext.Current.Request.IsAuthenticated ) { var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { var authTicket = FormsAuthentication.Decrypt(authCookie.Value); string data = authTicket.UserData; // data is empty !!! } } 解决方法
RedictFromLoginPage会覆盖您的cookie.删除此行并手动重定向(Response.Redirect).
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 防止用户在asp.net模型验证中输入表单时输入
- asp.net-mvc – 如何在向Db插入数据时自动生成asp.net mvc4
- 何时在ASP.NET MVC 2应用程序中提交NHibernate事务?
- 在ASP,C#和VB.Net中如何检索当前行号
- asp.net – Paypal自适应支付返回网址是两次调用
- ASP.NET TreeView和选择所选节点
- asp.net-mvc – IIS6中的ASP.NET MVC压缩选项
- asp.net-web-api – 如何在HttpReponseMessage上设置响应co
- asp.net-mvc-3 – ASP.NET MVC3 CSS框架
- asp.net-mvc-3 – MVC3 Ajax.ActionLink
推荐文章
站长推荐
- asp.net-mvc-3 – ASP.NET MVC 3,Razor Views和便
- asp.net-mvc – ASP.NET MVC UpdateModel容易受到
- asp.net-mvc – IIS不允许MVC应用程序控制Azure上
- asp.net-web-api – Web Api的动态连接字符串
- asp.net – 是否可以在Windows8上安装IIS 7.5或7
- asp.net-mvc – ASP.NET MVC Spark视图引擎
- ASP.NET MVC Route的几种配置方法
- asp.net – ThreadPools vs Own Threads用于长时
- 使用Asp.Net文本框的Bootstrap Datepicker
- asp.net-mvc-3 – 如何在带有剃刀的asp.net mvc3
热点阅读