我正在創建cookie並在成功登錄後存儲用戶名的值。如何在打開網站時訪問cookie。如果存在cookie,我想填充cookie值中的用戶名文本框。以及如何解密值以獲取用戶名。我通過從數據庫獲取用戶摘要來進行服務器端驗證。我使用VS 2010的C#如何在asp.net網站上獲取cookie值
FormsAuthenticationTicket tkt;
string cookiestr;
HttpCookie ck;
tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now,
DateTime.Now.AddYears(1), chk_Rememberme.Checked, "User Email");
cookiestr = FormsAuthentication.Encrypt(tkt);
ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
if (chk_Rememberme.Checked)
{
ck.Expires = tkt.Expiration;
ck.Path = FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(ck);
}
餅乾與名稱創建爲.YAFNET_Authentication和內容加密
Webconfig:
<forms name=".YAFNET_Authentication" loginUrl="Home.aspx"
protection="All" timeout="15000" cookieless="UseCookies"/>