Baking Cookies

Posts   
 
    
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 18-Apr-2005 21:23:52   

Hi mates simple_smile

I am having a problem with my Cookie recipe. stuck_out_tongue_winking_eye I can't seem to be able to create my cookie. Please have a look and see if i am missing something.

Here is the code that i use to create my cookie.

Dim ClientCookie As HttpCookie
                    Dim CookieName As String = CType(Current_Page, Base_Page).Local_Server.Client_System_Name
                    Dim CreatedCookie As Boolean = False

                    Variable_Name = Variable_Name.ToUpper
                    ClientCookie = Current_Page.Request.Cookies(CookieName)
                    If IsNothing(ClientCookie) Then
                        ClientCookie = New HttpCookie(CookieName)
                        CreatedCookie = True
                        ClientCookie.Domain = CookieName
                        ClientCookie.Expires = Now.AddDays(14)
                    End If
                    ClientCookie.Values.Remove(Variable_Name)
                    ClientCookie.Values.Add(Variable_Name, Value)

                    If CreatedCookie Then
                        Current_Page.Response.AppendCookie(ClientCookie)
                    Else
                        Current_Page.Response.Cookies.Add(ClientCookie)
                    End If

Here is the code that i use to read my cookie.

Dim ClientCookie As HttpCookie
                    Variable_Name = Variable_Name.ToUpper
                    Dim CookieName As String = CType(Current_Page, Base_Page).Local_Server.Client_System_Name
                    ClientCookie = Current_Page.Request.Cookies(CookieName)
                    If IsNothing(ClientCookie) Then
                        Return Nothing
                    Else
                        Return ClientCookie.Values(Variable_Name)
                    End If

Can anybody see something wrong?

wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 19-Apr-2005 14:58:57   

Any help?....... disappointed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39801
Joined: 17-Aug-2003
# Posted on: 19-Apr-2005 15:28:28   

When you enable your browser to view the cookies (always), what do you see, anything or nothing? Has the URL you're using a "_" ? If so, remove it.

Frans Bouma | Lead developer LLBLGen Pro
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 19-Apr-2005 15:48:52   

Otis wrote:

When you enable your browser to view the cookies (always), what do you see, anything or nothing? Has the URL you're using a "_" ? If so, remove it.

Hi Otis simple_smile Thanks for answering.

My browser allows cookies, i checked - i can receive cookies from other websites. disappointed The URL i am using does have ? because it is passing params. - Don't think i can remove it.

I compared my code to several examples on the .Net and it all looks simular. The only difference that i am picking up is that the examples on the Net is doing a redirect after creating the cookie and i am allowing the normal postback to continue.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39801
Joined: 17-Aug-2003
# Posted on: 19-Apr-2005 16:21:45   

wayne wrote:

Otis wrote:

When you enable your browser to view the cookies (always), what do you see, anything or nothing? Has the URL you're using a "_" ? If so, remove it.

Hi Otis simple_smile Thanks for answering.

My browser allows cookies, i checked - i can receive cookies from other websites. disappointed The URL i am using does have ? because it is passing params. - Don't think i can remove it.

No that's ok. Underscores aren't allowed in urls, and cookies won't work on these urls.

I compared my code to several examples on the .Net and it all looks simular. The only difference that i am picking up is that the examples on the Net is doing a redirect after creating the cookie and i am allowing the normal postback to continue.

But, do you receive a cookie popup after the postback? For the browser it doesn't matter what page you're redirecting: the same or another one. A cookie is a short piece of data coming back with the response. (and send by the browser in teh request). The host url etc. have to match the host url you're on. Please check if these are ok.

Frans Bouma | Lead developer LLBLGen Pro
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 21-Apr-2005 10:52:13   

Thanks Frans.

I got my cookie working simple_smile simple_smile simple_smile

It turned out that there was a "_" in the URL... Funny how that could affect the cookie - the rest of the application was working perfectly.

Thank you very much again. simple_smile