473,383 Members | 1,762 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,383 software developers and data experts.

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.Cookies.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.IsPostBack )
{
if ( Request.Cookies[ "test" ] != null )
TextBox1.Text = Request.Cookies[ "test" ].Value;
}

This "Request.Cookies" 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 1596
AddDays() doesn't alter the Expires value (the new value is a return value).
So, try cookie.Expires = DateTime.Now.AddDays (365);

"rb_atttt_nospam_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.Cookies.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.IsPostBack )
{
if ( Request.Cookies[ "test" ] != null )
TextBox1.Text = Request.Cookies[ "test" ].Value;
}

This "Request.Cookies" 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******@online.excite.comwrote in message
news:1D**********************************@microsof t.com...
AddDays() doesn't alter the Expires value (the new value is a return
value).
So, try cookie.Expires = DateTime.Now.AddDays (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
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...
9
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...
4
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...
6
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...
16
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...
6
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...
6
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.