Help on cookies ?

G

Guest

Dear all,

I try to make some test on how to use basic cookie but get some trouble in
the sens that I was not able to read back previous cretaed cookies.

In page_load event I have the following code :

If Not IsPostBack Then
If Request.Browser.Cookies Then
If Not IsNothing(Request.Cookies("PS")) Then
Session("Server") = Request.Cookies("PS").Value
txtServerName.Text = Session("Server")
End If

End If
end if

Somewhere in my code I set the cookie as follow :

If Request.Browser.Cookies Then
Dim ck_SrvName As New HttpCookie("PS")
ck_SrvName.Value = txtServerName.Text
Response.Cookies.Add(ck_SrvName)
End If

When I restart my application, my cookies object do not return it s content,
what am I doing wrong in here ?

thanks for your help
regards
serge
 
K

Karl Seguin

I'm not sure, but a guess is that your cookie is expiring. Are you closing
your browser and restarting when you
"restart your application" ?

If so, by default cookies only exist as long as the browser is open, to
change that you must give the cookie an expiry before adding it to the
response, something like:

cookie.Expires = DateTime.MaxValue ' Never Expires

Karl
 
G

Guest

Yes this is what I am doing, I am closing the browser each time to test that.
I will try to set the expiration parameter

thnaks
serge
 
V

Vadivel Kumar

And added to Karl's point..
When ever you're running session / cookie based programs, don't expect
proper results in debug mode.

Compile the code and execute in separate browser, not thru the F5'ing all
the time. So, that you can check the consistency of the code you've written.
 
G

Guest

Thansk , it works
I have add an expiration date and time an now when I colse my browser and
restart I am able to get the value back

by the wa where doe cokkies get sotre, I try to find out if my cooki has
been created, but how are they identify? sounds crypred

regards
serge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Cookies 1
Cookies 1
What is the proper way to use cookies? 1
Cookies will not expire (noob question) 4
Clearing cookies 2
cookies question 3
Cookies Count 2
problem with cookies and graphics 0

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top