Solved

deleting a subkey from a cookie

Posted on 2004-10-15
16
290 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
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!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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