1
讀我想讀AUTH票的用戶名(至極是TESTTEST
)從驗證cookie
-----登錄頁面------
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
"TESTTEST",
DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
String.Empty,
FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie authCookie = new HttpCookie(
FormsAuthentication.FormsCookieName,
encryptedTicket);
authCookie.Secure = true;
Response.Cookies.Add(authCookie);
FormsAuthentication.RedirectFromLoginPage("User", false);
--- ---保護頁-------
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
Label1.Text = ticket.Name;
結果:標籤文字"USER"
,而不是"TESTTEST"
- 我該怎麼辦?