473,666 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Reque st.Cookies("PS" )) Then
Session("Server ") = Request.Cookies ("PS").Value
txtServerName.T ext = 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.Valu e = txtServerName.T ext
Response.Cookie s.Add(ck_SrvNam e)
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 1306
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.MaxVal ue ' 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.mi crosoft.com> wrote in
message news:83******** *************** ***********@mic rosoft.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(Reque st.Cookies("PS" )) Then
Session("Server ") = Request.Cookies ("PS").Value
txtServerName.T ext = 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.Valu e = txtServerName.T ext
Response.Cookie s.Add(ck_SrvNam e)
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******** ******@TK2MSFTN GP14.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.MaxVal ue ' 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.mi crosoft.com> wrote in
message news:83******** *************** ***********@mic rosoft.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(Reque st.Cookies("PS" )) Then
Session("Server ") = Request.Cookies ("PS").Value
txtServerName.T ext = 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.Valu e = txtServerName.T ext
Response.Cookie s.Add(ck_SrvNam e)
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.MaxVal ue ' 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.mi crosoft.com> wrote in
message news:83******** *************** ***********@mic rosoft.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(Reque st.Cookies("PS" )) Then
Session("Server ") = Request.Cookies ("PS").Value
txtServerName.T ext = 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.Valu e = txtServerName.T ext
Response.Cookie s.Add(ck_SrvNam e)
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.MaxVal ue ' 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.mi crosoft.com> wrote in
message news:83******** *************** ***********@mic rosoft.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(Reque st.Cookies("PS" )) Then
Session("Server ") = Request.Cookies ("PS").Value
txtServerName.T ext = 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.Valu e = txtServerName.T ext
Response.Cookie s.Add(ck_SrvNam e)
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
1514
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 login and if username and password match then the user is redirected to the same page where he sees details of his message. What I have to do is this: in my db i have a table called users with the fields u_id, u_password and access. Access can...
18
2460
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 need: A system whereby the user only has to register ONCE and he will have automatic entry to ANY page without havinto to RE-LOGIN even if he comes in
0
1205
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 won't have anything to do with it. Can someone please help! The code below, going from aspx to aspx, works great the cookie as expected goes from qwerty to zxcvb and back. As soon as you hit the asp page, the cookie goes to asdfg and stays there...
3
2078
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 cookie = GetSessionCookie("MyCookie", "duh"); } private HttpCookie GetSessionCookie(string cookieKey, string cookieValue)
0
1227
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? The following code is a complete page that demonstrates my problem. If you save this as an .aspx and load it in a browser, it tells you it is creating the cookie. If you reload the page, it tells you it is changing the value. If you reload it...
3
1826
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 to tract the stage of the login process. LoginStatus = "1" denotes that the first part of the login process has been performed. LoginStatus = "2" denotes that the login process has been completed.
7
2627
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 like it to work properly so that a record count counts through all the books and genertates these numbers. watch out for line breaks <%@ Language=VBScript %> <% Option Explicit %> <!--#include file="DatabaseConnect.asp"-->
2
2315
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 <%@ Language=VBScript %> <% Option Explicit %> <!--#include file="DatabaseConnect.asp"--> <!--#include virtual="06winter/levini/database/adovbs.inc"-->
6
3348
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 the past in other places, and while the help was much appreciated, it seemed everyone just wanted to 'theoretically' explain how to do it, but when I tried to do it myself, I couldn't login. I want to simply pass the email address and password to...
0
8869
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.