Solved

deleting a subkey from a cookie

Posted on 2004-10-15
16
295 Views
Last Modified: 2008-02-01
hi, i want to delete a subkeyname from a cookie

i get an error on the line i have marked error :

Method 'String.remove' cannot be called with 1 argument(s).

i get the removeme as a sting with no probs... the subkeyname does exist in the cookie


 Dim j As Integer
        Dim x As Integer
        Dim removeMe As String
        Dim acookie = Request.Cookies("meds")
        j = acookie.Values.Keys.Count - 1
        For x = 0 To j
            If subkeyvalue(x) = e.CommandArgument Then
                removeMe = subkeyname(x).ToString
            End If
        Next
        acookie.value.remove(removeMe)   ****************** ERROR
        acookie.expires.datetime.now.adddays(1)
        Response.Cookies.Add(acookie)
        countCookie = j
        itemCookieCount()
        getTheData()

RSB
0
Comment
Question by:rsbadhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
16 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324049
Unfortunatelly you can not remove sub cookie :(
i suggest you to

Dim acookie = Request.Cookies("meds")
'modify the acookie value, then remove the old one by
Response.Cookies.Remove( Request.Cookies("meds") )
Response.Cookies.Add ( acookie )

HTH
B..M

0
 

Author Comment

by:rsbadhan
ID: 12324115
Response.Cookies.Remove( Request.Cookies("meds") )

gives a syntax error... vlaue of system.web... cannot be converted to string...

0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324154
i'm sorry, i have copied the code and didn't see that i've pasted there also

Response.Cookies.Remove( "meds" )

B..M
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rsbadhan
ID: 12324461
No Joy!
basically i have a shopping cart (productId's) stored in the cookie. If someone deletes n then i wan to remove the cookie and make a new one ... but it doesn't remove or exipre it, can be something with post back since it's inside a repeater?
let me post my full code for this section..

    Sub repeater1_itemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs)
        Dim j As Integer
        Dim x As Integer
        Dim removeMe As String
        Dim acookie = Request.Cookies("meds")
        j = acookie.Values.Keys.Count - 1
        For x = 0 To j
            If subkeyvalue(x) = e.CommandArgument Then
                removeMe = subkeyname(x).ToString
            End If
        Next

        Response.Cookies.Remove("meds")      ************* just remove the cookie then rewrite it with new values

        'For x = 0 To j
        '    If subkeyname(x) <> removeMe Then
        '        Dim newItem As String
        '        newItem = x
        '        acookie.Values.Item(newItem) = subkeyvalue(x).ToString
        '        acookie.Expires = DateTime.Now.AddDays(1)
        '        Response.Cookies.Add(acookie)
        '    End If
        'Next
        'countCookie = j
        'itemCookieCount()
        'getTheData()
        'End If
     
    End Sub
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324479
you have to remove the cookie and from the Request.Cookies collection
B..M
0
 

Author Comment

by:rsbadhan
ID: 12324506
how? is this not it?

Response.Cookies.Remove("meds")?

0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324577
this is only the Response collection

read this taken from msdn

ASP.NET includes two intrinsic cookie collections. The collection accessed through the Cookies collection of HttpRequest contains cookies transmitted by the client to the server in the Cookie header. The collection accessed through the Cookies collection of HttpResponse contains new cookies created on the server and transmitted to the client in the Set-Cookie header.



B..M
0
 

Author Comment

by:rsbadhan
ID: 12324608
any clue on the code that i can use to delete this cookie?
Thanks
RS
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324730
have you tried

Request.Cookies.Remove("meds")

?

B..M
0
 

Author Comment

by:rsbadhan
ID: 12324749
yep ... the cookie is still there...

may have to give up and work with session variables...
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324782
the session variables are much easy to maintain but you have to kill them manually - they do not have so easy to use maintaing like cookies

B..M
0
 

Author Comment

by:rsbadhan
ID: 12324800
may have no choice, i have tried this for hours...  tried both methods.
any last minute ideas?
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12324835
nothing else
0
 

Author Comment

by:rsbadhan
ID: 12324837
thanka for your help
0
 
LVL 20

Accepted Solution

by:
ihenry earned 500 total points
ID: 12389117

I created a simple ASP.NET project and use the following code. It is deleting a subkey from cookie without any problem.

'-- creating a cookie
HttpCookie newCookie = new HttpCookie("MyCookie")
newCookie("SubKey1") = "SubValue1"
newCookie("SubKey2") = "SubValue2"
newCookie("CreatedDate") = DateTime.Now.ToString()
Response.AppendCookie(newCookie)

'--- deleting a subkey from cookie
HttpCookie cookie = Request.Cookies("MyCookie")
If Not IsNothing(cookie) Then
      If cookie.HasKeys Then
            cookie.Values.Remove("SubKey2")
            Response.AppendCookie(cookie)
      End If
End If
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question