Problem with cookies, can't delete cookie

U

Urban Bettag

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Trouble with a simple cookie 3
Cookies C# 3
problem with cookies 3
Create cookie in what event when leaving page? 1
Cookies 1
Cookies 1
Problem with retrieving cookie in ASP.net 2
Cookies Count 2

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top