473,403 Members | 2,222 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,403 software developers and data experts.

Help: Deleting individual cookie subkeys

Help!

I've made a cookie with a key called 'List' and
subkey 'item3' and assigned it a value of "3"

Response.Cookies("List")("item3")="3"

How do I now delete the subkey "item3" without
deleting any other subkeys that might be in 'List'???
J
Nov 19 '05 #1
2 2633
Hi James,

This is a more complicated problem, deleting an individual subkey. You
cannot simply reset the expiration date for the cookie, because that would
remove the entire cookie instead of a single subkey. The solution instead is
to manipulate the cookie's Values collection, which holds the subkeys. First
recreate the cookie by getting it from the Request.Cookies object. You can
then call the Remove method of the Values collection, passing to the Remove
method the name of the subkey to delete. Then, as usual, you add the
modified cookie to the Response.Cookies collection so it will be sent in its
modified form back to the browser.
The following code shows how to delete a subkey. In the sample, the name of
the subkey to remove is specified in a variable.

Dim subkeyName As String
subkeyName = "userName"
Dim aCookie As HttpCookie = Request.Cookies("userInfo")
aCookie.Values.Remove(subkeyName)
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)I hope this helps,Regards,Stuart
"James" <ja*********@ntlworld.com> wrote in message
news:5f*****************@newsfe3-win.ntli.net...
Help!

I've made a cookie with a key called 'List' and
subkey 'item3' and assigned it a value of "3"

Response.Cookies("List")("item3")="3"

How do I now delete the subkey "item3" without
deleting any other subkeys that might be in 'List'???
J

Nov 19 '05 #2
Hello Stuart,

I found the same info as you on the msdn website.
Needless to say I had difficulty getting the code to
work and hense my original post.

I've spent a day on the code to get cookies to act as
a temporary shopping cart. I'm still working on it - however,
this is donkey-work, I've found the solution(s).

The most challenging problem I've had of late. Soon as
I've finished the assignment this is all for, I will post the
useful stuff to a vbforum on the net to spread a little joy :)

Thanks for your reply,

James
"Stuart A Hill" <xy*@abc.com.bin> wrote in message
news:eg**************@TK2MSFTNGP15.phx.gbl...
Hi James,

This is a more complicated problem, deleting an individual subkey. You
cannot simply reset the expiration date for the cookie, because that would
remove the entire cookie instead of a single subkey. The solution instead is to manipulate the cookie's Values collection, which holds the subkeys. First recreate the cookie by getting it from the Request.Cookies object. You can
then call the Remove method of the Values collection, passing to the Remove method the name of the subkey to delete. Then, as usual, you add the
modified cookie to the Response.Cookies collection so it will be sent in its modified form back to the browser.
The following code shows how to delete a subkey. In the sample, the name of the subkey to remove is specified in a variable.

Dim subkeyName As String
subkeyName = "userName"
Dim aCookie As HttpCookie = Request.Cookies("userInfo")
aCookie.Values.Remove(subkeyName)
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)I hope this helps,Regards,Stuart
"James" <ja*********@ntlworld.com> wrote in message
news:5f*****************@newsfe3-win.ntli.net...
Help!

I've made a cookie with a key called 'List' and
subkey 'item3' and assigned it a value of "3"

Response.Cookies("List")("item3")="3"

How do I now delete the subkey "item3" without
deleting any other subkeys that might be in 'List'???
J


Nov 19 '05 #3

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

Similar topics

1
by: YT | last post by:
Couple of quick ASP (3.0) Cookie questions: 1/ I'm using a cookie in my asp script to place cookies (within a key) so my code looks like: Response.Cookies( "quoteform" )( "name" ) = Session(...
0
by: John Smith | last post by:
I have a cookie that contains two subkeys. I am trying to read one of the subkeys via the <asp:CookieParameter>, but I can't seem to specify which subkey to get. ASP.NET seems to only want to...
14
by: Alec S. | last post by:
Hi, I'm using JavaScript and Cookies for some customization in a web page. There may be several values in the cookie with names that are not known at runtime. I need a way of deleting them. ...
3
by: vbMark | last post by:
Hello, In regards to the Registry... Can someone give me an example of how to list an unknown number of subkeys under a key, and put the key names in one column of a listbox, and the key...
1
by: Michal A. Valasek | last post by:
Hello, I have problem deleting cookies and cookies values (using framework version 1.1 on W2003). When I try to remove entire cookie, by calling Response.Cookies.Remove("Test"), nothing...
4
by: macro | last post by:
when I use HttpWebRequest with CookieContainer object that handles cookies, i make more than one request and needs to handle cookies being added and removed between requests, just like a regular...
4
by: D. | last post by:
Hi, I defined some cookies in order to pass values between pages in my application. The problem is that when i request them with: cookie = Request.Cookies("mycookie") x = cookie.Value (suppose...
1
by: method | last post by:
I am trying to delete registery key encluding all its subkeys . I want to delete the bold part HKEY_CURRENT_USER, "Software\xyz\foldername\" using an api that i found on the net but i keep...
0
by: ananth | last post by:
Hi All, I have a code that generates list of installed softwares available on the pc but the code works fine when written in a console application in visual basic 2005. How can the same...
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...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.