How to read cookie subkey from CookieContainer

I am having problem reading the cookies subkey value,

I have a cookies which name is created like this but I am not able to read its index value


Please find the code attached

Public Function getValue(ByVal strCookieKey As String, ByVal strCookieIndex As String, ByVal strDomain As String) As String
        Dim request As HttpWebRequest = CType(WebRequest.Create("http://" & strDomain), HttpWebRequest)
        request.Proxy = WebProxy.GetDefaultProxy() ' If you want to use default settings of IE
        request.Timeout = -1
        request.KeepAlive = False
        request.CookieContainer = New CookieContainer()
        Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
        'Print the properties of each cookie.
        Dim cook As Cookie
        For Each cook In response.Cookies
            If cook.Name = "WiggleBasket" Then
                'Return cook.Value
                Return Server.HtmlEncode(cook.Values(0))
            End If
        Next cook
        Return ""
    End Function

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

who stored the cookie? did the same application /domain store the cookie? what was the "path" attribute of the cookie .. try setting it as "/"
shieldguyAuthor Commented:
cookie is created on the same domain but in my code i want to access the cookie value easily but iinstead i have to put a for loop and then match each cooke witn the desired cookie subkey name and then get the name

why cant i read its value like this

value = HttpContext.Current.Response.Cookies("Basket")("BasketID")

Ted BouskillSenior Software DeveloperCommented:
You have it backwards.  If you want to read the cookie use value = HttpContext.Current.Request.Cookies("Basket")("BasketID")

Response is used to transmit the cookie back to the user, Request is the cooked you received from the users computer.
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Ted BouskillSenior Software DeveloperCommented:
Sorry Cookie not 'Cooked'
shieldguyAuthor Commented:
Actually I am reading the cookies from the other web site using the httpwebrequest then i storing them in the cookiecontainer so may be thats why the request.cookie is not available ?
>>Actually I am reading the cookies from the other web site using the httpwebrequest
yes, that is the reason why i asked whether it is stored by the same web site .. imagine if you can read cookies stored by another website, anyone can just loop through or guess the name of the cookies stored in a client PC and use it for malicious intent .. so there is a restrictiion implemented by all browsers wherein you cannot read cookies stored by another website ..


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shieldguyAuthor Commented:
Thanks Mate
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.