【发布时间】:2011-01-08 13:23:08
【问题描述】:
我正在尝试在我正在开发的 c# web 应用程序中创建和读取表单身份验证 cookie。
我创建工单
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, "myData", DateTime.Now, DateTime.Now.AddMinutes(60), true, "Hello");
// Now encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName,encryptedTicket);
// 将 cookie 添加到传出 cookie 集合中 Response.Cookies.Add(authCookie);
然后当我使用以下方式取回票时:
HttpCookie authCookie = Context.Request.Cookies[cookieName];
FormsAuthenticationTicket authTicket = null;
authTicket = FormsAuthentication.Decrypt(authCookie.Value)
我可以看到 authTicket 现在拥有所有数据,cookie 创建日期,到期日期,name="mydata"... 等等。
但 dataValue 中没有任何内容...我期待“Hello”出现。
当我调试时,我可以看到它在加密之前就在票证中......我想它在解密中丢失了?
有什么帮助吗?
【问题讨论】: