473,698 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cookies not persisted on client side

rb

Hi,

This is a very silly (and newbie) question but...

I started a new site; added on default.aspx a text box and a button. On Button Click, I do this:

HttpCookie cookie;
cookie = new HttpCookie( "test", TextBox1.Text );
cookie.Expires. AddDays( 365 );
cookie.Domain = "localhost" ;
this.Response.C ookies.Add( cookie );

but the cookie won't persist after browser is closed and reopened (IE and FireFox equally).

In Page Load I have

if ( !Page.IsPostBac k )
{
if ( Request.Cookies[ "test" ] != null )
TextBox1.Text = Request.Cookies[ "test" ].Value;
}

This "Request.Cookie s" is always null and I have absolutely no idea why. I played a bit with web.config but I really don't know what must be set to make cookies persist. My objective is just to save various values and I have no plans to enable authentication once this site is done.

Thanks in advance.

rb
Jun 20 '07 #1
2 1604
AddDays() doesn't alter the Expires value (the new value is a return value).
So, try cookie.Expires = DateTime.Now.Ad dDays (365);

"rb_atttt_nospa m_sheermomentum .com (rb)" wrote:
>
Hi,

This is a very silly (and newbie) question but...

I started a new site; added on default.aspx a text box and a button. On Button Click, I do this:

HttpCookie cookie;
cookie = new HttpCookie( "test", TextBox1.Text );
cookie.Expires. AddDays( 365 );
cookie.Domain = "localhost" ;
this.Response.C ookies.Add( cookie );

but the cookie won't persist after browser is closed and reopened (IE and FireFox equally).

In Page Load I have

if ( !Page.IsPostBac k )
{
if ( Request.Cookies[ "test" ] != null )
TextBox1.Text = Request.Cookies[ "test" ].Value;
}

This "Request.Cookie s" is always null and I have absolutely no idea why. I played a bit with web.config but I really don't know what must be set to make cookies persist. My objective is just to save various values and I have no plans to enable authentication once this site is done.

Thanks in advance.

rb
Jun 20 '07 #2
rb

"Siva M" <sh******@onlin e.excite.comwro te in message
news:1D******** *************** ***********@mic rosoft.com...
AddDays() doesn't alter the Expires value (the new value is a return
value).
So, try cookie.Expires = DateTime.Now.Ad dDays (365);
Nicely spotted mistake in my code but it's still a no-go. Cookies still
won't persist.

.... Played a bit more with my code and, apparently, cookie.Domain =
"localhost" was the other part of the problem. When I removed that line, the
cookie finally got saved. I'm not sure why is this the case? Is it because
I'm not redirecting the page or because P3P in follow-up was missing (as
described in thread "Cookies Disappearing") or...

Thanks a lot.

rb

Jun 20 '07 #3

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

Similar topics

5
1844
by: Scott | last post by:
On an Intranet Web application I'm working on, I need to display a Pop-up that shows the users what report changes have occurred. This may happen once a week or more and I need a way for the users to turn-off this Pop-up after they've reviewed the changes. Currently, I'm debating whether to use cookies or build a table that will set flags. I'm not sure what the best solution to take would be. Does anyone know what would be the best...
9
7851
by: Agoston Bejo | last post by:
Hi, I searched around everywhere on the net, but could not find a simple example of detecting if cookies are enabled - on server side, and without moving from one page to another. This should be a very basic functionality, so I am reluctant to believe that there's no way to simply test it in a server-side script. Anyone? Thx, Agoston
4
2226
by: Rickey Tom | last post by:
This has to be a very common question, but my search did not come up with an answer. I needed to set an expiration time for a cookie. In .NET, is seems that the server-side code is used to set the expiration date of the cookie. More specifically, I've seen several examples (from the Microsoft site) where the cookie information, including the expiration date is set on the server. I wonder how this can work. If the client and server do not...
6
1584
by: Pete Davis | last post by:
I've never done anything with cookies. What I'm trying to do is very straight-forward, but for some reason, it just doesn't seem to want to work. I have a helper class with some static methods. Two are for setting and getting the name of the user to/from a cookie: public static string GetSiteUser(HttpRequest request) { HttpCookie userCookie = request.Cookies; if (null == userCookie || null == userCookie.Value) {
16
11048
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have read documents on the CookieCollection property of HttpWebRequest. Currently, I have the functionality in my code to be able to accept cookies, and return them upon a new HttpWebRequest; however, upon further inspection of the returning...
6
3497
by: Mike | last post by:
Hi, I've been using httpwebrequest / xmlserverhttp to log into a website via POST. I've received all the response headers back, some of which contain the "set-cookie" headers. When performing any other action on the website I need to submit the JSESSION id and BSESSIONID as part of my POSTS. I was just wondering where these session ids originate, from the server
6
7845
by: dawson | last post by:
I started off by trying to use the HttpCapabilitiesBase.Cookies Property (Note: This property is new in the .NET Framework version 2.0) however it kept on returning true even when I disabled cookies in both FireFox and Internet Explorer. After a bit of googling I found that a lot of people were creating cookies, then re-reading them; obviously if they could re-read the cookie then they knew that the client's browser accepts cookies!...
2
6030
by: archana | last post by:
Hi all, I am developing one web service. I am not clear about some concept of web servic. I want to ask Do web service always support cookie-based session? or i can have session without cookies? And if i want to use custom cookies will those cookies get stores on service side always?
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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
9031
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...
0
8871
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...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.