views:

1601

answers:

2

Hi

I have my own linq to sql database with a nice login method which gives me back a user.

I have followed the 101 examples there on the web as to how to add the cookie to the client.

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,
                _u.id.ToString(), 
                DateTime.Now, 
                DateTime.Now.AddDays(14), 
                true, 
                "hi", 
                FormsAuthentication.FormsCookiePath);

        string hash = FormsAuthentication.Encrypt(ticket);

        HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);   

        if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;

        //Response.Cookies.Add(cookie);

        //FormsAuthentication.RedirectFromLoginPage(_u.name, _remember);
        FormsAuthentication.SetAuthCookie(_u.name, _remember);

And sure enough it does get added. But when I inspect it, its expiration says end of session, not two weeks as specified. So when a user tries to come back to the site after closing the browser, they have to log in.

Any ideas?

+2  A: 

I fail.

In firefox i had it so cookies were killed after i kill the browser.

qui
A: 

Well, thanks at least for posting all the code summarized to be referenced in one place :)

Nexxas