我使用以下代码设置cookie过期:
// remove existing cookies.
request.Cookies.Clear();
response.Cookies.Clear();
// ... serialize and encrypt my data ...
// now set the cookie.
HttpCookie cookie = new HttpCookie(AuthCookieName, encrypted);
cookie.Expires = DateTime.Now.Add(TimeSpan.FromHours(CookieTimeOutHours)
我正在考虑设置一个选项来保持用户登录的可能性。现在,我了解到会话可以用于允许用户在每个页面上导航,而无需在每个页面上重新输入登录信息,直到浏览器关闭,会话丢失为止。cookie将存储在客户端,并且有一个持续时间,直到它到期或用户删除该cookie为止。
我在想,我可以把两者结合起来
创建一个db表(id、user_id、cookie_token、is_active)
用户日志,在db表中创建一行,将用户连接到存储在客户端浏览器(system)上的cookie_token。
- Each time a token is created, check to see if the u
我创建了一个cookie,它设置了正确的过期时间,但是当我更新cookie并用调试器检查它时,过期时间已经过去了。怎么一回事?
' Cookie Helper: Updates cookie with the selected source ids
Protected Sub UpdateCookieFor(ByVal cookieName As String, ByVal sourceIds As String)
' Update cookie if it exists
If Request.Cookies(cookieName) IsNot Nothing
在ASP.NET MVC2应用程序中,我们有标准的登录操作...
if (ValidateUser(model.Email, model.Password)
{
FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
...
其中,SetAuthCookie的第二个参数是createPersistentCookie,包含以下文档:
createPersistentCookie
Type: System.Boolean
true to create a persistent cookie
(o