shieldguy
asked on
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
HttpContext.Current.Respon se.Cookies ("Basket") ("BasketID ")
Please find the code attached
Thanks
I have a cookies which name is created like this but I am not able to read its index value
HttpContext.Current.Respon
Please find the code attached
Thanks
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
response.Close()
Return ""
End Function
who stored the cookie? did the same application /domain store the cookie? what was the "path" attribute of the cookie .. try setting it as "/"
ASKER
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.Respon se.Cookies ("Basket") ("BasketID ")
thanks
why cant i read its value like this
value = HttpContext.Current.Respon
thanks
You have it backwards. If you want to read the cookie use value = HttpContext.Current.Reques t.Cookies( "Basket")( "BasketID" )
Response is used to transmit the cookie back to the user, Request is the cooked you received from the users computer.
Response is used to transmit the cookie back to the user, Request is the cooked you received from the users computer.
Sorry Cookie not 'Cooked'
ASKER
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Mate