473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Clearing cookies

I am practicing Cookies in .NET. Its working fine but when I want to
clear my cookies, the statement,

Response.Cookies.Clear

does not work. What gives?

Here's what I do:
(1) Login page

There's a "Remember me on this computer checkbox". When the user
presses the login button, I do this:
Sub btnLogin_Click(sender As Object, e As EventArgs)

if chkRemember.Checked = True Then
Dim ckUserName As HttpCookie = new HttpCookie("UserName")
ckUserName.value = Trim(txtUserName.Text)
ckUserName.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckUserName)
ckUserName = Nothing

Dim ckPassword As HttpCookie = new HttpCookie("Password")
ckPassword.value = Trim(txtPassword.Text)
ckPassword.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckPassword)
ckPassword = Nothing
End If

Response.Redirect("AnotherPage.aspx")
End Sub

Sub Page_Load(sender As Object, e As EventArgs)
if Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Response.Redirect("AnotherPage.aspx")
End If
End Sub
(2) AnotherPage.aspx

Sub Page_Load(sender As Object, e As EventArgs)
If Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Dim StrUserName As String =
Request.Cookies("UserName").value.ToString
Response.Write("Welcome, " & StrUserName & "!")
Response.Write("<br/><p>If you are not " & StrUserName & ",
then click <a href='ClearCookies.aspx'>here</a>.</p>")
Else
Response.Write("You are a cookieless bastard.")
End If
End Sub
(3) ClearCookies.aspx

Sub Page_Load(sender As Object, e As EventArgs)
Response.Cookies.Clear
Response.Redirect("index.aspx")
End Sub

Nov 21 '05 #1
4 1848

Hello ,,
Deleting a cookie - physically removing it from the user's hard disk - is a
variation on modifying it. You cannot directly remove a cookie because the
cookie is on the user's computer. However, you can get the browser to delete
the cookie for you. The technique is to modify the cookie as described above
(that is, create a new cookie with the same name) but to set the cookie's
expiration to a date earlier than today. When the browser checks the
cookie's expiration, the browser will discard the now-outdated cookie.

Deleting any one cookie is therefore the same technique as creating that
cookie, except that you use a date earlier than today. The following example
is slightly more interesting than deleting a single cookie - it shows one
way to delete all the cookies for the current domain:

Dim i As Integer
Dim cookieName As String
Dim limit As Integer = Request.Cookies.Count - 1
For i = 0 To limit
aCookie = Request.Cookies(i)
aCookie.Expires = DateTime.Now.AddDays(-1)
Response.Cookies.Add(aCookie)
Nextregards Michel Posseth "Water Cooler v2" <wt*****@yahoo.com> wrote in
message news:11*********************@z14g2000cwz.googlegro ups.com...
I am practicing Cookies in .NET. Its working fine but when I want to
clear my cookies, the statement,

Response.Cookies.Clear

does not work. What gives?

Here's what I do:
(1) Login page

There's a "Remember me on this computer checkbox". When the user
presses the login button, I do this:
Sub btnLogin_Click(sender As Object, e As EventArgs)

if chkRemember.Checked = True Then
Dim ckUserName As HttpCookie = new HttpCookie("UserName")
ckUserName.value = Trim(txtUserName.Text)
ckUserName.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckUserName)
ckUserName = Nothing

Dim ckPassword As HttpCookie = new HttpCookie("Password")
ckPassword.value = Trim(txtPassword.Text)
ckPassword.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckPassword)
ckPassword = Nothing
End If

Response.Redirect("AnotherPage.aspx")
End Sub

Sub Page_Load(sender As Object, e As EventArgs)
if Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Response.Redirect("AnotherPage.aspx")
End If
End Sub
(2) AnotherPage.aspx

Sub Page_Load(sender As Object, e As EventArgs)
If Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Dim StrUserName As String =
Request.Cookies("UserName").value.ToString
Response.Write("Welcome, " & StrUserName & "!")
Response.Write("<br/><p>If you are not " & StrUserName & ",
then click <a href='ClearCookies.aspx'>here</a>.</p>")
Else
Response.Write("You are a cookieless bastard.")
End If
End Sub
(3) ClearCookies.aspx

Sub Page_Load(sender As Object, e As EventArgs)
Response.Cookies.Clear
Response.Redirect("index.aspx")
End Sub

Nov 21 '05 #2

Hello ,,
Deleting a cookie - physically removing it from the user's hard disk - is a
variation on modifying it. You cannot directly remove a cookie because the
cookie is on the user's computer. However, you can get the browser to delete
the cookie for you. The technique is to modify the cookie as described above
(that is, create a new cookie with the same name) but to set the cookie's
expiration to a date earlier than today. When the browser checks the
cookie's expiration, the browser will discard the now-outdated cookie.

Deleting any one cookie is therefore the same technique as creating that
cookie, except that you use a date earlier than today. The following example
is slightly more interesting than deleting a single cookie - it shows one
way to delete all the cookies for the current domain:

Dim i As Integer
Dim cookieName As String
Dim limit As Integer = Request.Cookies.Count - 1
For i = 0 To limit
aCookie = Request.Cookies(i)
aCookie.Expires = DateTime.Now.AddDays(-1)
Response.Cookies.Add(aCookie)
Nextregards Michel Posseth "Water Cooler v2" <wt*****@yahoo.com> wrote in
message news:11*********************@z14g2000cwz.googlegro ups.com...
I am practicing Cookies in .NET. Its working fine but when I want to
clear my cookies, the statement,

Response.Cookies.Clear

does not work. What gives?

Here's what I do:
(1) Login page

There's a "Remember me on this computer checkbox". When the user
presses the login button, I do this:
Sub btnLogin_Click(sender As Object, e As EventArgs)

if chkRemember.Checked = True Then
Dim ckUserName As HttpCookie = new HttpCookie("UserName")
ckUserName.value = Trim(txtUserName.Text)
ckUserName.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckUserName)
ckUserName = Nothing

Dim ckPassword As HttpCookie = new HttpCookie("Password")
ckPassword.value = Trim(txtPassword.Text)
ckPassword.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckPassword)
ckPassword = Nothing
End If

Response.Redirect("AnotherPage.aspx")
End Sub

Sub Page_Load(sender As Object, e As EventArgs)
if Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Response.Redirect("AnotherPage.aspx")
End If
End Sub
(2) AnotherPage.aspx

Sub Page_Load(sender As Object, e As EventArgs)
If Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Dim StrUserName As String =
Request.Cookies("UserName").value.ToString
Response.Write("Welcome, " & StrUserName & "!")
Response.Write("<br/><p>If you are not " & StrUserName & ",
then click <a href='ClearCookies.aspx'>here</a>.</p>")
Else
Response.Write("You are a cookieless bastard.")
End If
End Sub
(3) ClearCookies.aspx

Sub Page_Load(sender As Object, e As EventArgs)
Response.Cookies.Clear
Response.Redirect("index.aspx")
End Sub

Nov 21 '05 #3
see this for more cookie info :

http://msdn.microsoft.com/library/de...cookies101.asp

regards

Michel Posseth

"m.posseth" <mi*****@nohausystems.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Hello ,,
Deleting a cookie - physically removing it from the user's hard disk - is
a variation on modifying it. You cannot directly remove a cookie because
the cookie is on the user's computer. However, you can get the browser to
delete the cookie for you. The technique is to modify the cookie as
described above (that is, create a new cookie with the same name) but to
set the cookie's expiration to a date earlier than today. When the browser
checks the cookie's expiration, the browser will discard the now-outdated
cookie.

Deleting any one cookie is therefore the same technique as creating that
cookie, except that you use a date earlier than today. The following
example is slightly more interesting than deleting a single cookie - it
shows one way to delete all the cookies for the current domain:

Dim i As Integer
Dim cookieName As String
Dim limit As Integer = Request.Cookies.Count - 1
For i = 0 To limit
aCookie = Request.Cookies(i)
aCookie.Expires = DateTime.Now.AddDays(-1)
Response.Cookies.Add(aCookie)
Nextregards Michel Posseth "Water Cooler v2" <wt*****@yahoo.com> wrote in
message news:11*********************@z14g2000cwz.googlegro ups.com...
I am practicing Cookies in .NET. Its working fine but when I want to
clear my cookies, the statement,

Response.Cookies.Clear

does not work. What gives?

Here's what I do:
(1) Login page

There's a "Remember me on this computer checkbox". When the user
presses the login button, I do this:
Sub btnLogin_Click(sender As Object, e As EventArgs)

if chkRemember.Checked = True Then
Dim ckUserName As HttpCookie = new HttpCookie("UserName")
ckUserName.value = Trim(txtUserName.Text)
ckUserName.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckUserName)
ckUserName = Nothing

Dim ckPassword As HttpCookie = new HttpCookie("Password")
ckPassword.value = Trim(txtPassword.Text)
ckPassword.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckPassword)
ckPassword = Nothing
End If

Response.Redirect("AnotherPage.aspx")
End Sub

Sub Page_Load(sender As Object, e As EventArgs)
if Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Response.Redirect("AnotherPage.aspx")
End If
End Sub
(2) AnotherPage.aspx

Sub Page_Load(sender As Object, e As EventArgs)
If Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Dim StrUserName As String =
Request.Cookies("UserName").value.ToString
Response.Write("Welcome, " & StrUserName & "!")
Response.Write("<br/><p>If you are not " & StrUserName & ",
then click <a href='ClearCookies.aspx'>here</a>.</p>")
Else
Response.Write("You are a cookieless bastard.")
End If
End Sub
(3) ClearCookies.aspx

Sub Page_Load(sender As Object, e As EventArgs)
Response.Cookies.Clear
Response.Redirect("index.aspx")
End Sub


Nov 21 '05 #4
see this for more cookie info :

http://msdn.microsoft.com/library/de...cookies101.asp

regards

Michel Posseth

"m.posseth" <mi*****@nohausystems.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Hello ,,
Deleting a cookie - physically removing it from the user's hard disk - is
a variation on modifying it. You cannot directly remove a cookie because
the cookie is on the user's computer. However, you can get the browser to
delete the cookie for you. The technique is to modify the cookie as
described above (that is, create a new cookie with the same name) but to
set the cookie's expiration to a date earlier than today. When the browser
checks the cookie's expiration, the browser will discard the now-outdated
cookie.

Deleting any one cookie is therefore the same technique as creating that
cookie, except that you use a date earlier than today. The following
example is slightly more interesting than deleting a single cookie - it
shows one way to delete all the cookies for the current domain:

Dim i As Integer
Dim cookieName As String
Dim limit As Integer = Request.Cookies.Count - 1
For i = 0 To limit
aCookie = Request.Cookies(i)
aCookie.Expires = DateTime.Now.AddDays(-1)
Response.Cookies.Add(aCookie)
Nextregards Michel Posseth "Water Cooler v2" <wt*****@yahoo.com> wrote in
message news:11*********************@z14g2000cwz.googlegro ups.com...
I am practicing Cookies in .NET. Its working fine but when I want to
clear my cookies, the statement,

Response.Cookies.Clear

does not work. What gives?

Here's what I do:
(1) Login page

There's a "Remember me on this computer checkbox". When the user
presses the login button, I do this:
Sub btnLogin_Click(sender As Object, e As EventArgs)

if chkRemember.Checked = True Then
Dim ckUserName As HttpCookie = new HttpCookie("UserName")
ckUserName.value = Trim(txtUserName.Text)
ckUserName.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckUserName)
ckUserName = Nothing

Dim ckPassword As HttpCookie = new HttpCookie("Password")
ckPassword.value = Trim(txtPassword.Text)
ckPassword.Expires = System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckPassword)
ckPassword = Nothing
End If

Response.Redirect("AnotherPage.aspx")
End Sub

Sub Page_Load(sender As Object, e As EventArgs)
if Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Response.Redirect("AnotherPage.aspx")
End If
End Sub
(2) AnotherPage.aspx

Sub Page_Load(sender As Object, e As EventArgs)
If Not (Request.Cookies("UserName") Is Nothing And _
Request.Cookies("Password") Is Nothing) Then
Dim StrUserName As String =
Request.Cookies("UserName").value.ToString
Response.Write("Welcome, " & StrUserName & "!")
Response.Write("<br/><p>If you are not " & StrUserName & ",
then click <a href='ClearCookies.aspx'>here</a>.</p>")
Else
Response.Write("You are a cookieless bastard.")
End If
End Sub
(3) ClearCookies.aspx

Sub Page_Load(sender As Object, e As EventArgs)
Response.Cookies.Clear
Response.Redirect("index.aspx")
End Sub


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
0
by: RobbRoss | last post by:
I'm stuck using C# on a project and am trying to clear the Cookies. The Response.Cookies.Clear(); is not working. What needs to be done to make this remove the cookies? I'm testing this on my...
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
1
by: Anubis Cain Dante | last post by:
I am trying to programmatically clear the forms and passwords in internet explorer. I am well aware of how to do this (via the UI) in Internet Options and I've already accomplished programmatically...
3
by: tshad | last post by:
Is there a way to manually clear the FormsAuthentication cookie? I want to be able to clear the cookie before going to a specific page to force the logon page to be called before the page. ...
2
by: Water Cooler v2 | last post by:
I am practicing Cookies in .NET. Its working fine but when I want to clear my cookies, the statement, Response.Cookies.Clear does not work. What gives? Here's what I do:
1
by: Anshul | last post by:
Hello, I'm using an Iframe to display user's detail if logged in and login form if logged out. Its working very fine in Mozilla but not working in IE. Cookies are getting destroyed but still...
6
by: =?Utf-8?B?R2Vv?= | last post by:
Hi, I use lots of sessions. I want to clear the unwanted sessions when I leave a page. I cant use ViewState as it will slow down the pages. Could some one help me on this?
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.