1

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?

4
  • _remember is true? It needs to be for the cookie to be persistent. Commented Nov 26, 2008 at 15:34
  • But i just debugged it to check I'm not insane :p And I can confirm it is true. Gah this is annoying. Commented Nov 26, 2008 at 15:36
  • You might still be insane though. Commented Nov 26, 2008 at 16:58
  • 1
    are you sure you "debugged to check I'm not insane"??? btw - how could you "and I can confirm it is true"?? :) Commented Mar 19, 2010 at 19:39

2 Answers 2

3

This particular error was caused because I had the browser set to erase cookies when it was closed.

Sign up to request clarification or add additional context in comments.

Comments

-1

I have the same problem and I solve on login Page_Load
First validate User.Identity is correct
if true we have a valid user!!!.
if false remove old cookie (See this link http://forums.asp.net/t/1227365.aspx/1)
this last part is to prevent new cookie can't save correctly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.