相关疑难解决方法(0)

在.NET 3.5中回发后,FormsAuthentication不保留UserData字段

FormsAuthenticationTicket从零开始创建了一个,但发现在以后检索它时,UserData它不会回来.这是使用的代码:

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        1,
                        user.UserId,
                        DateTime.Now,
                        DateTime.MaxValue,
                        false,
                        user.UserType);

HttpCookie cookie = new HttpCookie(
     FormsAuthentication.FormsCookieName, 
     FormsAuthentication.Encrypt(ticket));

Response.Cookies.Add(cookie);
Run Code Online (Sandbox Code Playgroud)

但是,当读到下一个时Request,我发现该UserData字段现在是空的:

string encryptedCookie = Request.Cookies[ FormsAuthentication.FormsCookieName ].Value;
FormsAuthenticationticket ticket = FormsAuthentication.Decrypt(encryptedCookie);
Assert.IsTrue( ticket.UserData.Length == 0 ); //TRUE!
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

asp.net cookies formsauthentication

2
推荐指数
1
解决办法
4720
查看次数

标签 统计

asp.net ×1

cookies ×1

formsauthentication ×1