我使用C#和MVC5使用此代码来创建自己的cookie:了rememberMe设置Cookie的到期时间,但在萤火虫出现过期的会话
// Prepare the ticket
HttpContext.Response.Cookies.Clear();
FormsAuthenticationTicket ticket =
new FormsAuthenticationTicket(1,
"MYNAME",
DateTime.Now,
DateTime.Now.AddDays(10), // <<- Expires 10 days
true,
null);
// Encrpt the ticket
string encryptedCookie = FormsAuthentication.Encrypt(ticket);
// Create new cookie
HttpCookie cookie = new HttpCookie("MYNAME", encryptedCookie);
cookie.Path = FormsAuthentication.FormsCookiePath;
// Send the Cookie back to the browser
HttpContext.Response.Cookies.Add(cookie);
上的Web.config我设置的名称为
<authentication mode="Forms">
<forms name="MYNAME" loginUrl="~/Account/Login"></forms>
</authentication>
但是,当我看萤火虫,则饼干显示为“MYNAME”,但“到期”设置为Session。
事实上,当我关闭浏览器时,cookie会消失,当我回到网站时,我总是需要重新登录。所有其他浏览器也是如此。
我在做什么错?
他们都有..所有以某种方式让他们的过期设置为“会议”在浏览器级别相同的问题。问题不在于我的池回收,而是因为关闭浏览器时cookie过期。如果我不关闭它,它会保持活动状态,并在我返回网站时自动登录。 – Johnny
好吧在配置中添加超时,并尝试。 把它像超时= 1200,并试一试 –
不,仍然没有工作。对此我有一个小希望:-) – Johnny