473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

HttpCookie Error.

I don't understand the error i'm getting on this page. Is this a bug or
am I doing something wrong?
Exception Details: System.InvalidCastException: Unable to cast object of
type 'System.String' to type 'System.Web.HttpCookie'.

Source Error:

Line 24:
Line 25: For Each ckie As System.Web.HttpCookie In
Request.Cookies
Line 26: If ckie.Name = "uid" Then
Line 27: Session.Item("uid") = ckie.Value

Source File: c:\inetpub\index.aspx.vb Line: 25
*** Sent via Developersdex http://www.developersdex.com ***
Feb 12 '07 #1
2 3582
Howdy,

-- begin vbsuxx code :) --
Dim cookie As HttpCookie

' more efficient approach
For i As Integer = 0 To Request.Cookies.Count
cookie = Request.Cookies(i)
Next

' another approach
For Each key As String In Request.Cookies.AllKeys
cookie = Request.Cookies(key)
Next

-- end vbsuxx code

hope it helps

Milosz
"Terry Olsen" wrote:
I don't understand the error i'm getting on this page. Is this a bug or
am I doing something wrong?
Exception Details: System.InvalidCastException: Unable to cast object of
type 'System.String' to type 'System.Web.HttpCookie'.

Source Error:

Line 24:
Line 25: For Each ckie As System.Web.HttpCookie In
Request.Cookies
Line 26: If ckie.Name = "uid" Then
Line 27: Session.Item("uid") = ckie.Value

Source File: c:\inetpub\index.aspx.vb Line: 25
*** Sent via Developersdex http://www.developersdex.com ***
Feb 13 '07 #2
Sorry, small bug (i'm c# guy and i don't program vb often), should be :

For i As Integer = 0 To Request.Cookies.Count - 1
cookie = Request.Cookies(i)
Next

--
Milosz
"Milosz Skalecki [MCAD]" wrote:
Howdy,

-- begin vbsuxx code :) --
Dim cookie As HttpCookie

' more efficient approach
For i As Integer = 0 To Request.Cookies.Count
cookie = Request.Cookies(i)
Next

' another approach
For Each key As String In Request.Cookies.AllKeys
cookie = Request.Cookies(key)
Next

-- end vbsuxx code

hope it helps

Milosz
"Terry Olsen" wrote:
I don't understand the error i'm getting on this page. Is this a bug or
am I doing something wrong?
Exception Details: System.InvalidCastException: Unable to cast object of
type 'System.String' to type 'System.Web.HttpCookie'.

Source Error:

Line 24:
Line 25: For Each ckie As System.Web.HttpCookie In
Request.Cookies
Line 26: If ckie.Name = "uid" Then
Line 27: Session.Item("uid") = ckie.Value

Source File: c:\inetpub\index.aspx.vb Line: 25
*** Sent via Developersdex http://www.developersdex.com ***
Feb 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: chris | last post by:
I'm struggling with using the HttpCookie object on a code behind. Used in the page works great I'm getting a: Type 'HttpCookie' is not define I've tried adding the namespace to the vb form but no...
1
by: Ivan Demkovitch | last post by:
Hi! System.Net.Cookie class offers greater flexibility for working with Cookies compare to System.Web.HttpCookie. Is there any way to work with cookies thru System.Net.Cookie instead of...
0
by: Chris | last post by:
Just a curiosity: Is it standard practice to UrlEncode and UrlDecode cookie values? I wouldn't have even stumbled across this except I noticed that when I retrieve a cookie that was set with...
1
by: Waqqas Farooq | last post by:
Can I add more than 1 values in a cookie? e.g if i create a httpcookie then the syntax would be like this: Dim myCookie as new HttpCookie("myCookieName") myCookie.Value = "myval1"...
1
by: baleixo | last post by:
Hello, i´m creating a httpcookie with some content (e.g: "Cçã"). In our development environment when i try to get the value of the cookie it returns "Cçã". (no problem in this environment -...
0
by: Nuro de Matos Carvalho | last post by:
Hi all, I'm having a strange problem using cookies, setting values with special characters. Set cookie data: <snipet> string encryptedTicket = FormsAuthentication.Encrypt(authTicket);...
3
by: ulabala | last post by:
I was trying to retrieve the cookie collection and display the domain to which those cookies were written to, but I always see a NULL value for the domain property. Can anyone shed some light?...
3
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
What properties on a HttpCookie give invalid information when you read it from the Request object? For example if you run this code, I believe the domain, expires, and HttpOnly do not tell the...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Does anyone know if it is possible to change the datatype of a string into an HTTPCookie? I tried CType and it would not let me do it.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.