我正在创建一个在30天后过期的cookie ..
以下是c#
中的代码
e.UserID - >用户名,
e.rememberMe - >真
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
"UserID",
DateTime.Now,
DateTime.Now.AddDays(30),
e.rememberMe,
e.UserID,
FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie.
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
任何想法
答案 0 :(得分:9)
您应该设置cookie对象的Expires
属性,因为cookie不知道您放入其中的内容:
Response.Cookies.Add(
new HttpCookie(FormsAuthentication.FormsCookieName, encTicket) {
Expires = ticket.Expiration
});