我遇到cookie过期的问题。 虽然我在3天后设定了到期但是cookie 关闭浏览器后会被删除。
这是我的代码。
Private Sub setMyCookie(ByVal username As String)
'------- check for user input; if checkbox is checked on login.
If CheckBox1.Checked Then
'------- check if browser support cookies
If (Request.Browser.Cookies) Then
'------- check if the cookie with name 'myCookie' exists on users machine.
If (Request.Cookies("myCookie") Is Nothing) Then
'------- create a cookie & write username to it
Response.Cookies("myCookie").Value = username
'------- with expiry of 3 days
Response.Cookies("myCookie").Expires = Now.AddDays(3)
'------- write username to the cookie
'Response.Cookies("myCookie").Item("UserLoginName") = username
Else
Response.Cookies("myCookie").Value = username
Response.Cookies("myCookie").Expires = Now.AddDays(3)
End If
End If
End If
End Sub