Re: how to make cookies into an array?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



But you are trying to convert "test1" to a cookie. That is a string, not a cookie. You must specifically create an instance of HttpCookie, fill in its constructor or fields as needed, and then store it. I haven't used that object myself, but the code would be something like this.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim oneCookie As HttpCookie
Dim i As Integer

For counter = 1 To 5
oneCookie = New HttpCookie
' !!! Fill in all of oneCookie's fields here, then...
allCookies.Add("test" & counter, oneCookie)
Next counter

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005

Hi,

thanks for replying ...

I tried this (it must be a loop because i never don't know in advance
how
many cookies i need)
But i get the error: "value of type string cannot be converted to
system.web.httpcookie"
How can i give the value of the cookie?
Thanks
Dim allCookies As Generic.Dictionary(Of String, HttpCookie)
Dim i As Integer
Dim cc(5) As String
For i = 1 To 5
allCookies.Add(cc(i), "test" & i)
Next
"Tim Patrick" <invalid@xxxxxxxxxxxxxxxxxxx> schreef in bericht
news:e3b469762e408c8e1a20e2d96d8@xxxxxxxxxxxxxxxxxxxxxxxxx

If you are using VB2005, you can switch to one of the Generic
collections that includes a key so that you can look up the cookie by
name.

Dim allCookies As Generic.Dictionary(Of String, HttpCookie)

Add new cookies to the dictionary this way:

allCookies.Add(cookieName, theCookieItself)

Access the cookie this way:

theRetrievedCookie = allCookies(cookieName)

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
Hi,

I need several cookies depending of an variable (x), so i defined a
HttpCookie() as an array.
My problems:
1)I get the error: Object reference not set to an instance of an
object.
2)My second question is: how to request those cookies, because there
is no
name?
Thanks
André
I did:
x=5
Dim cok(x) As New HttpCookie 'can't give a name to the cookie
....
for k=1 to x
cok(k).Value = "cookie" & k
Response.Cookies.Add(cok(k))
next
-----------------------------------
recovering the cookies?
for i=1 to x
cok(i) = Request.Cookies("??")
next


.



Relevant Pages

  • Re: DESPERATE: FormsAuthentication Problem
    ... >>> database and create a semicolon delimited string listing the roles ... >>> them in the forms authentication cookie. ... >>> Dim authTicket As FormsAuthenticationTicket = New ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Ticket disappears when browser is closed
    ... be careful - if the cookie is save to the users harddrive - anyone who has access to that directory can grab the cookie and bypass authentication. ... Dim New DatabaseUser ... Dim userData As String = DatabaseUser.UserData ... ByVal PersonID As Integer, ByVal roles As String) ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Cannot retrieve UserData in Forms Authentication
    ... and am getting user data back from the cookie. ... I assume your setting the ticket in a login page. ... >Dim authTicket As New FormsAuthenticationTicket(1, ... >Dim encryptedTicket As String = ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Authenticating a user from a Web Service called by JavaScript func
    ... I have a .NET application which contains a web service that authenticates ... Public Function Login(ByVal UserName As String, ... Dim adAuth As AdFormsAuthClassLibrary.LdapAuthentication = New ... 'Create a cookie, and then add the encrypted ticket to the ...
    (microsoft.public.dotnet.framework.webservices)
  • Ticket disappears when browser is closed
    ... I am new to ASP.Net Forms Authentication but read the newsgroup thorughly. ... Dim New DatabaseUser ... Dim encTicket As String = FormsAuthentication.Encrypt ... 'Create the cookie. ...
    (microsoft.public.dotnet.framework.aspnet.security)