Solved

deleting a subkey from a cookie

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

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now