I want to use persistent cookies for my login page. For example, the user
types in his username and password. He can check a box and the system should
remember his username on a next visit. I have the following code, generating
and reading the cookie seems to work fine.
If I uncheck the box, the cookie should be removed or reset. For some
reason, the cookie will not be changed and remains in the cookie folder
(C:\Document and Settings\<user>\Cookies).
<Script runat="server">
Sub Page_Load
getCookie()
End Sub
Sub btnLogin_click(...)
...
If chkPersistCookie.Checked Then
setCookie()
Else
deleteCookie()
End If
End Sub
Sub getCookie()
...
End Sub
Sub setCookie()
...
End Sub
Sub deleteCookie()
Dim objCookie As HttpCookie = Request.Cookies("test")
If Not(objCookie Is Nothing) Then
objCookie.Values.Remove("username")
objCookie.Values.Remove("remember")
objCookie.Expires = DateTime.Now().AddDays(-1)
objCookie.Cookies.Add(objCookie)
End if
End Sub
</Script>
What's wrong with the code? Do I need to check any other permissions?
Thanks,
Urban