Non-persistent cookie

M

Marco Rispoli

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!
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top