By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,003 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Non-persistent cookie

P: n/a
I am using this function to write a cookie:

private static void SaveCookie(string CookieName, string CookieValue, bool
Persistent)
{
HttpContext.Current.Response.Cookies[CookieName].Value = CookieValue;
HttpContext.Current.Response.Cookies[CookieName].Path = "/";
HttpContext.Current.Response.Cookies[CookieName].Domain =
ConfigurationSettings.AppSettings["cookie_domain"].ToString();
if (Persistent) {HttpContext.Current.Response.Cookies [CookieName].Expires
= DateTime.Now.AddMonths(12);}
}

The cookie gets written correctly except that if I pass false to Persistent
(and Expires doesn't get set, I stepped through the code, I am sure of
that), the cookie is still persistent.(if I close the browser and re-open it
the cookie is still there).

I had similar code in traditional ASP and it was working fine. Is there a
step I am missing?

The default value of the Expires property appears to be {1/1/1}

PS: I am not using formsauthentication and I don't plan to do it.

Thanks!

--
Marco Rispoli - NJ, USA / PP-ASEL
My on-line aviation community -> http://www.thepilotlounge.com
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Have you tried -1 as the expiry value when you do not
want persistence?

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Marco Rispoli" <ri******@optonline.net> wrote in message
news:0N***********************@news4.srv.hcvlny.cv .net...
I am using this function to write a cookie:

private static void SaveCookie(string CookieName, string CookieValue, bool Persistent)
{
HttpContext.Current.Response.Cookies[CookieName].Value = CookieValue;
HttpContext.Current.Response.Cookies[CookieName].Path = "/";
HttpContext.Current.Response.Cookies[CookieName].Domain =
ConfigurationSettings.AppSettings["cookie_domain"].ToString();
if (Persistent) {HttpContext.Current.Response.Cookies [CookieName].Expires = DateTime.Now.AddMonths(12);}
}

The cookie gets written correctly except that if I pass false to Persistent (and Expires doesn't get set, I stepped through the code, I am sure of
that), the cookie is still persistent.(if I close the browser and re-open it the cookie is still there).

I had similar code in traditional ASP and it was working fine. Is there a step I am missing?

The default value of the Expires property appears to be {1/1/1}

PS: I am not using formsauthentication and I don't plan to do it.

Thanks!

--
Marco Rispoli - NJ, USA / PP-ASEL
My on-line aviation community -> http://www.thepilotlounge.com

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.