Tôi đang tạo cookie và lưu trữ giá trị của tên người dùng sau khi đăng nhập thành công. Làm thế nào tôi có thể truy cập cookie khi trang web được mở. Nếu cookie tồn tại tôi muốn điền vào hộp văn bản tên người dùng từ giá trị cookie. Và cách giải mã giá trị để lấy tên người dùng. Tôi đang thực hiện xác thực phía máy chủ bằng cách lấy các userdetails từ cơ sở dữ liệu. Tôi đang sử dụng vs 2010 với C#Cách lấy giá trị cookie trong trang web asp.net
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);
}
cookie được tạo ra với tên như .YAFNET_Authentication và nội dung được mã hóa
webconfig:
<forms name=".YAFNET_Authentication" loginUrl="Home.aspx"
protection="All" timeout="15000" cookieless="UseCookies"/>