RJV*_*RJV 0 c# asp.net asp.net-mvc
我正在创建一个在30天后到期的cookie.
这是c#
e.UserID中的代码- > username,e.rememberMe - > true
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));
Run Code Online (Sandbox Code Playgroud)
任何的想法
您应该设置Expirescookie对象的属性,因为cookie不知道您放入其中的内容:
Response.Cookies.Add(
new HttpCookie(FormsAuthentication.FormsCookieName, encTicket) {
Expires = ticket.Expiration
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1117 次 |
| 最近记录: |