473,383 Members | 1,742 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,383 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 19 '05 #1
2 4863
Water Cooler v2 <wt*****@yahoo.com> ha scritto:
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?


Response.Cookies("Password").Expires=DateTime.Now. AddDays(-1)
Response.Cookies("...").Expires=DateTime.Now.AddDa ys(-1)
Response.Cookies("...").Expires=DateTime.Now.AddDa ys(-1)

--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
Nov 19 '05 #2
indeed - and here is why:

Response.Cookies.Clear

just clears the current response buffer of cookie headers

which won't affect the browser's cookie store

to get the browser to dump the cookies
you have to set the cookies to expire in the past

Nov 19 '05 #3

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...
6
by: Stephane | last post by:
Hi, I have a login page where if the user wants his access codes to be saved are set into a cookie. In the logout page, I want to delete those cookies. I tried this and this is not working at...
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. ...
4
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?
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.