Select Categories Below
Advertisement
Start Your Own Q&A Site
Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.
Status: Closed Points: 75 Time: 07:53 - Jul 19, 2006
dustPuppy
Hi all, I have been trying to remove some cookies that I set, but without luck. I'm using asp.net 1.1 and c#. First I have the problem that I can access the cookies collection two ways: this.response.cookies and this.request.cookies, but which should I use? I did use request and then just set the cookie to an empty string, but the idea was to remove it completely. When i tried to use this.Request.Cookies.Remove("xxx"); it was removed in the VS.NET watch, but was "back" next time the user accessed the site. I'm not sure what I'm doing wrong, but it's probably something simple. I look forward to some help with this.
Categories:
Add Categories
When adding more than one category, separate them with commas.
PeterNZ
Date:: Jul 19, 2006
Time:: 21:39
Hi, you use the Request.Cookies collection to check if a cookie is on the users machine. You create a Cookie adding it to the Response.Cookies collection. The Cookie handling is a bit strange in ASP.NET 1.x. It seems that if you access Request.Cookies, all Cookies from Response.Cookies get copied over to Request.Cookies. So checking for an existing cookie using Request.Cookies is ok. If you add a cookie, use Response.Cookie. If you want to access this cookie, use Request.Cookie and the new cookie gets copied over. Confusing? You bet! You shouldn't (or bette you can't easily) delete a cookie. A cookie gets removed from the clients machine if it expires. Set the Expires proprty of the cookie to now: Response.Cookies["TheCookie"].Expires = DateTime.Now; The operating system should clean out the expired cookie. Hope this helped Peter
rcastagna
Date:: Jul 21, 2006
Time:: 20:27
hey, dustPuppy... Peter got most of the cookie stuff correct. Just an augmentation to what he put down for the expiration, I usually set the cookie to expire one day ago, just to make sure that it cant be used: Response.Cookies["myCookies"].Expires = DateTime.Now.AddDays(-1); You can remove values in the cookie, as well. Let's say you've got a cookie and one of the keys is "foo" with the value of "bar" myCookie.Values.Add("foo", "bar"); Once you're read in the cookie (using Request.Cookies as Peter shows above) you can remove the value for "foo". myCookie = Requst.Cookies["theCookie"]; myCookie.Values.Remove("foo"); now, you've got to add the cookie back into the Cookie collection: Response.Cookies.Add(myCookie); If you want to see what is contained in the cookie now you can use: Response.Write(myCookiesValues.ToString()); Have fun... Ric
Date:: Jul 24, 2006
Time:: 03:59
dustPuppy, I "fat-fingered" the last statement in my post above...not enough coffee, I guess. It should read: Response.Write(myCookie.Values.ToString()); That'll work much better... Ric
Date:: Jul 25, 2006
Time:: 01:59
Thanks, Peter and Ric. I'm surprised it's not more intuitive to do, but well now I've learned it :)
jgivoni
Date:: Feb 18, 2007
Time:: 12:14
Cookies get set and read via HTTP headers, and once you understand the flow, it gets much easier! Setting and reading cookies is a dialog between the server and the client. When setting a cookie, the server adds it to the response headers and when the browser reads the headers, it should set the cookie accordingly. Therefore, always use the Response collection to set them. Next time the client requests a page on your domain, it will add the (unexpired) cookies for that domain to the request headers, which will then be read by your server script (the Request collection). The reason why cookies reasonably could copied from Response to Request automatically is that otherwise the cookie would still show as unset, even though you have just set it, until the user hits the next page or refreshes the current. But actually it kind of cheating when the server does this :-) Jakob
Question Answered
This question has been closed, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Questions
Hi is there a way to retrieve the loop count in XSLT
how do repair this problem: every times i opened my laptop it will suddenly n...
How i get the hp pavilion dv6-3054tx laptop bottom base assembly as a sparepa...
I don't have AOL browser but privacy scan shows hundreds of files/cookies fro...
wireless keyboard has stopped working
need validation controller for textbox in java
You have 100 characters to use
Rank
Expert
Points
1.
10279
2.
6493
3.
5596
4.
4848
5.
3487
6.
2840
7.
2770
8.
2303
9.
1820
10.
917
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software