[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to set Cookie.Expire time?

Posted on 2004-08-05
6
Medium Priority
?
774 Views
Last Modified: 2012-08-13
Hoi all...
I have trouble with the following code:
--------
                  DateTime dtNow = DateTime.Now;
                  TimeSpan tsMinute = new TimeSpan(365, 0, 0, 0);
                  HttpCookie myCookie = new HttpCookie(cookieName);
                  myCookie.Expires = dtNow + tsMinute;
                  myCookie["memberID"] = iMemberID.ToString();
                  myCookie["memberNick"] = sMemberNick;
                  myCookie["memberPassword"] = sMemberPassword;
                  this.Response.Cookies.Add(myCookie);
----
Now I check, what the expire time for the cookie is:
----
                  myCookie = inPage.Request.Cookies[cookieName];
                  Response.Write("this cookie expires: "+myCookie.Expires);
----
I always get:
01.01.0001 00:00:00

The idea how to set the cookie is taken from here:
http://www.csharphelp.com/archives/archive179.html

Can someone tell me how I tell my cookie to life for 365 days from now?

Thank you.
0
Comment
Question by:Smoerble
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:mahanatti
ID: 11725181
0
 

Author Comment

by:Smoerble
ID: 11725261
This contains
---
DateTime dtExpiry = DateTime.Now.AddDays(iDaysToExpire);
Response.Cookies[cookiename].Expires =dtExpiry;
---
I did that too, same result as above: expire time seems not to be correct.
Any other idea?
0
 

Author Comment

by:Smoerble
ID: 11725364
Update:
I checked what the browser says about the cookie:
the date is set correctly... so the question is, why doesn't it display the correct date in my code?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Assisted Solution

by:NipNFriar_Tuck
NipNFriar_Tuck earned 600 total points
ID: 11727243
Hmmm... I am wondering if you are cheking your cookie after another page hit?  If you are checking your cookie after setting it you are looking at the wrong object.  You set your cookie on Response and check on Request.  Also, if cookies are turned off on the browser then this may happen.
0
 
LVL 9

Accepted Solution

by:
s_sansanwal earned 1400 total points
ID: 11732548
0
 

Author Comment

by:Smoerble
ID: 11738452
Ok, as stated in
http://www.dotnet247.com/247reference/msgs/48/240266.aspx
the cookie does not send back the correct dateTime when using ....Expires.
Thank you.

If anybody has any other idea, please feel free to share ;)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question