473,473 Members | 4,189 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Q: Can't Remove Cookie

Hi,

I have a C# ASP.Net page allow users to enter their name and will set those
value as cookie after click on "Submit" button. In addition, if user click
on "Change" button, the cookie should be remove. By replacing the same
cookie name with negative expire date, things just work fine.

Unfortunatelly, if I try to use the Cookies.Clear() or Cookies.Remove()
method, the cookie just doesn't remove. Anyone know why?

void ButtonSubmit_Click(object sender, EventArgs e) {
HttpCookie myCookie = new HttpCookie("aCookie");
myCookie.Values["firstname"] = TextBoxFirstname.Text.Trim();
myCookie.Values["lastname"] = TextBoxLastname.Text.Trim();

DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,3,0);
myCookie = dt + ts;

Response.Cookies.Add(myCookie);

Response.Redirect("same.aspx");
}
}
}

// This will work
void ButtonChange_Click(object sender, EventArgs e) {
HttpCookie myCookie = new HttpCookie("aCookie");
myCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(myCookie);
Response.Redirect("same.aspx");
}

// This will NOT work
void ButtonChange_Click(object sender, EventArgs e) {
Response.Cookies.Clear();
Response.Redirect("same.aspx");
}

Thank you.

--
Soul


Nov 18 '05 #1
0 1110

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

Similar topics

8
by: lkrubner | last post by:
I was trying to set a cookie before I called session_start() and it was giving me an error. But isn't sessions really just a cookie? Why would it matter if I sent a cookie before session_start? Can...
3
by: HorseGeek | last post by:
I can't find a cookie that my code is writing. The behavior of my webpages indicates that the cookie IS being written SOMEPLACE. However, I can't find it. My client does not want the code going...
1
by: Mike | last post by:
Hello, I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP (I want to read and write cookies from both javascript and ASP) for example in...
0
by: Urban Bettag | last post by:
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...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
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...
0
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
24
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I see in javascript if a web browser accepts cookies?...
3
by: webster5u | last post by:
Miss/Mr. Programmer, I have a idea to remove the cookie value from a website after all browser closed. It is like session kept in server and eliminate after all browser closed. My purpose is...
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.