Cookies with Subkeys in ASP.NET

lopy_is_me

New Member
Oh this is an article/tutorial I'd like to see: HOW TO HANDLE COOKIES IN .NET!!! Cookies seem to have been completely redone with respect to subkeys. Now not only do we have the response.cookies and request.cookies collections (which contain different indexes, by the way!), we have these objects: System.Web.HTTPCookie, System.Web.HTTPCookieColletion, System.Net.Cookie, and System.Net.CookieColletion, as well as containers and exceptions!<BR><BR>OH MY! Here is why I've run into trouble with all of this. In the Classic ASP days you could do this...<BR><BR>---user does some surfing---<BR>'set cookie<BR>response.cookies("app1")("email") = "user@email.com"<BR>response.cookies("app1").Expires = Now + 365<BR><BR>--- user closes browser, comes back does more surfing----<BR>'set another cookie<BR>response.cookies("app1")("phonenumber") = "555.555.5555"<BR>response.cookies("app1").Expires = Now + 365<BR><BR>OK that's great, now you have 2 cookies values as subkeys for APP1 that will last a year from the setting of the last cookie. WELL in ASP.NET, if I do the same thing, setting that "phonenumber" cookies destroys the value in the "email" cookie!<BR><BR>So then I start messing with the new HTTPCookie object and collections, trying to add subkeys to existing cookie keys, and in that case the opposite was true, I could set the "email" key first, but then when I set the "phonenumber" key, that value got destroyed when the session ended.<BR><BR>So, then I look at the System.Net.Cookie classes and its members which seem to have NO support for subkeys.<BR><BR>==== ON TO DELETION ====<BR><BR>Also, if I have many cookies with subkeys and I have grouped my app's cookies (this is all on an intranet), I could have these collections...<BR><BR>response.cookies("app1")("value1")<BR>response.cookies("app1")("value2")<BR><BR>response.cookies("app2")("value1")<BR>response.cookies("app2")("value2")<BR><BR>NOW let's say I want to get rid of all values in APP1, but not APP2 (don't ask why, just trust me that there are good reasons for all this). I can't set objects of the HTTPCookie Class and change values to Nothing or "" and expect the cookie to go away, I can't even do this...<BR><BR>dim oCookie as HTTPCookie<BR>oCookie = request.cookies("app1")<BR>oCookie.value = http://aspmessageboard.com/archive/index.php/""<BR>oCookie.expires = date.now.AddDays(-1)<BR><BR>because when I do that and close the browser (IE6), the cookie is still there!<BR><BR>I can do this...<BR><BR>response.cookies("app1").value = ""<BR><BR>but you would think that I could use all the new classes to handle the creation, truncation, concatenation, and deletion of all cookies values and their subkey values and expiration dates.<BR><BR>OK, now someone post the quick 5 line answer to my problem and I'll go sit in this corner over here.<BR><BR>thanks<BR>
 
Back
Top