Setting Cookie.Expires

J

Joe

I'm trying to set the Expires property of a cookie in a control by doing the
following:
this.Context.Response.Cookies["mycookie"].Expires =
DateTime.Today.AddDays(1);

But when I refresh the page and check the same
this.Context.Response.Cookies["mycookie"].Expires it has the default date
1/1/0001.

Any idea what I'm doing wrong?

Thanks,
Joe
 
J

Joe

Sorry I made a mistake in the posting. When I check
this.Context.Request.Cookies["mycookie"].Expires it is the default value.
 
G

George Ter-Saakov

Here is the thing you need to realize.

Request.cookies and Response.cookies are 2 different collections
So if you set correct expiration date in Response.Cookie when you check
Request.Cookie will still have old expiration date.

There need to be roundtrip to browser and back for Request.Cookie to become
what you have set it to in previous request.

George.


Joe said:
Sorry I made a mistake in the posting. When I check
this.Context.Request.Cookies["mycookie"].Expires it is the default value.

Joe said:
I'm trying to set the Expires property of a cookie in a control by doing
the following:
this.Context.Response.Cookies["mycookie"].Expires =
DateTime.Today.AddDays(1);

But when I refresh the page and check the same
this.Context.Response.Cookies["mycookie"].Expires it has the default date
1/1/0001.

Any idea what I'm doing wrong?

Thanks,
Joe
 
S

Steven Cheng

Hi Joe,

As for the Cookie expire time, it does have been set on the cookie (you add
into the Response.Cookies collection). The problem that you didn't see the
expire value the next time the page submit is because the client browser or
the request http message doesn't include the expire date value. I 've
performed test by adding cookie with expire date assigned and post the page
again. I use some utility to trace the http request/response and found that
the response http message will include expire date(you asigned) for cookie,
however, thet request message will only include name/value pair for
cookies.

I think this is a fixed behavior of webbrowser since it will maintain the
expire/validation of cookies. If a cookie has expired, the browser will no
longer send it (and remove it at client).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: (e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response

from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take

approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution.

The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump

analysis issues. Issues of this nature are best handled working with a
dedicated Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Joe" <[email protected]>
References: <[email protected]>
Subject: Re: Setting Cookie.Expires
Date: Thu, 6 Mar 2008 16:15:16 -0500
Sorry I made a mistake in the posting. When I check
this.Context.Request.Cookies["mycookie"].Expires it is the default value.

Joe said:
I'm trying to set the Expires property of a cookie in a control by doing
the following:
this.Context.Response.Cookies["mycookie"].Expires =
DateTime.Today.AddDays(1);

But when I refresh the page and check the same
this.Context.Response.Cookies["mycookie"].Expires it has the default date
1/1/0001.

Any idea what I'm doing wrong?

Thanks,
Joe
 
S

Steven Cheng

Hi Joe,

Does the information in my last reply help you some? If there is anything
else need help, welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: (e-mail address removed).
--------------------t
From: (e-mail address removed) ("Steven Cheng")
Organization: Microsoft
Date: Fri, 07 Mar 2008 03:13:05 GMT
Subject: Re: Setting Cookie.Expires
Hi Joe,

As for the Cookie expire time, it does have been set on the cookie (you add
into the Response.Cookies collection). The problem that you didn't see the
expire value the next time the page submit is because the client browser or
the request http message doesn't include the expire date value. I 've
performed test by adding cookie with expire date assigned and post the page
again. I use some utility to trace the http request/response and found that
the response http message will include expire date(you asigned) for cookie,
however, thet request message will only include name/value pair for
cookies.

I think this is a fixed behavior of webbrowser since it will maintain the
expire/validation of cookies. If a cookie has expired, the browser will no
longer send it (and remove it at client).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: (e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#noti f
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response

from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take

approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution.

The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump

analysis issues. Issues of this nature are best handled working with a
dedicated Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Joe" <[email protected]>
References: <[email protected]>
Subject: Re: Setting Cookie.Expires
Date: Thu, 6 Mar 2008 16:15:16 -0500
Sorry I made a mistake in the posting. When I check
this.Context.Request.Cookies["mycookie"].Expires it is the default value.

Joe said:
I'm trying to set the Expires property of a cookie in a control by doing
the following:
this.Context.Response.Cookies["mycookie"].Expires =
DateTime.Today.AddDays(1);

But when I refresh the page and check the same
this.Context.Response.Cookies["mycookie"].Expires it has the default date
1/1/0001.

Any idea what I'm doing wrong?

Thanks,
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top