473,406 Members | 2,549 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,406 software developers and data experts.

Help on cookies ?

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
Nov 19 '05 #1
4 1296
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"serge calderara" <se************@discussions.microsoft.com> wrote in
message news:83**********************************@microsof t.com...
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

Nov 19 '05 #2
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.
--
Vadivel Kumar
http://blogs.wdevs.com/varahe

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Oj**************@TK2MSFTNGP14.phx.gbl...
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"serge calderara" <se************@discussions.microsoft.com> wrote in
message news:83**********************************@microsof t.com...
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


Nov 19 '05 #3
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

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"serge calderara" <se************@discussions.microsoft.com> wrote in
message news:83**********************************@microsof t.com...
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


Nov 19 '05 #4
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

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"serge calderara" <se************@discussions.microsoft.com> wrote in
message news:83**********************************@microsof t.com...
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


Nov 19 '05 #5

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

Similar topics

0
by: collie | last post by:
Hi, I have an asp page that needs to create 2 different cookies: one for the admin and one for the user. The code that I have to work with was created by someone else. the page first requires to...
18
by: | last post by:
Please help. After a number of wrong turns and experiments I need advice on login management system to secure our web pages without inconveniencing our visitors or our internal staff. What I...
0
by: Bennett F. Dill | last post by:
Thanks for reading. I'm having problems with cookies from asp to asp.net and back! It seems like I can set a cookie in asp.net fine, and alter it at will, as soon as asp touches it, asp.net...
3
by: Calvin KD | last post by:
Hi everyone, Can someone tell me what's wrong with the way that i read a cookie as below: private void Page_Load(object sender, System.EventArgs e) { Response.Cookies.Clear(); HttpCookie...
0
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
3
by: Phillip N Rounds | last post by:
I'm having trouble with using cookies to monitor the stages of login. I have a two stage Registration page ( register.aspx ) and my target page ( MyPage.aspx ) I'm using a cookie named LoginStatus...
7
by: isaac2004 | last post by:
hi i have a basic asp page that acts as an online bookstore. on my cart page i am having trouble generating 3 numbers; a subtotal, a shipping total, and a final price. here is my code i would...
2
by: isaac2004 | last post by:
hi i am creating a basic asp site that uses cookies to manage a cart for an online store. whenever i open this page without adding anything to the cart. i get an error message. here is my code ...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.