Cookies will get deleted, no matter what

G

Guest

Easy to describe that problem: The cookies will be deleted after the user
closes the browser, but I have set persistance to true. Code:

------

TicketForPremium = new FormsAuthenticationTicket(1, UserID, DateTime.Now,
DateTime.Now.AddHours(10), true, "1");
TicketForPremiumCrypted = FormsAuthentication.Encrypt(TicketForPremium);

Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,
TicketForPremiumCrypted));
-------

I've tested local (win2000, IIS 5) and on a server (win2003, IIS 6) and
with different browsers (IE, firefox, opera) and the results are always the
same.

I am using .net 1.1
 
B

bruce barker \(sqlwork.com\)

cookies are session cookies if no expiration date has been set. your code
does not set an expiration date for the cookie (only to the session data),
so its a session cookie. try:

HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName,
TicketForPremiumCrypted);
cookie.Expires = DateTime.Now.AddHours(10), // persist cookie
Response.Cookies.Add(cookie);

-- bruce (sqlwork.com)


"the friendly display name"
 
G

Guest

Thank you, that was it.

bruce barker (sqlwork.com) said:
cookies are session cookies if no expiration date has been set. your code
does not set an expiration date for the cookie (only to the session data),
so its a session cookie. try:

HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName,
TicketForPremiumCrypted);
cookie.Expires = DateTime.Now.AddHours(10), // persist cookie
Response.Cookies.Add(cookie);

-- bruce (sqlwork.com)


"the friendly display name"
 

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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top