Solved

deleting a subkey from a cookie

Posted on 2004-10-15
16
282 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
  • 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 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