asp.net – 尽管设置了FormsAuthenticationTicket的UserData属性为空
发布时间:2020-05-24 09:23:47 所属栏目:asp.Net 来源:互联网
导读:出于某种原因,我的身份验证cookie的UserData属性为空.这是代码: var authCookie = FormsAuthentication.GetAuthCookie(userName, rememberUser.Checked);// Get the FormsAuthenticationTicket out of the encrypted cookievar ticket =
|
出于某种原因,我的身份验证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 – 在.net 3.5 SP1中设置表单的操作会在编译时导致
- asp.net-mvc – 如果使用HTML内容,我可以写入内联吗?
- ASP.NET API版本控制
- 具有Entity Framework Code Only和ASP.NET MVC的模块化应用
- asp.net-mvc – Url.Action with RouteValueDictionary wit
- asp.net-mvc – MVC中的模型含义
- asp.net-mvc-3 – MVC 3模型属性未在html.action调用的部分
- asp.net-core – MVC 6安装为Windows服务(ASP.NET Core 1.0
- asp.net-mvc – 使用ASP.NET MVC 2 AsyncController实现长时
