gpt4 book ai didi

asp.net - 尽管已设置,FormsAuthenticationTicket 的 UserData 属性仍为空

转载 作者:行者123 更新时间:2023-12-02 06:28:52 26 4
gpt4 key购买 nike

由于某种原因,我的身份验证 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 - 尽管已设置,FormsAuthenticationTicket 的 UserData 属性仍为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16594905/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com