Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

deleting a subkey from a cookie

Posted on 2004-10-15
16
Medium Priority
?
312 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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