Authentication/Session cookie deleting after browser close

前端 未结 2 623
借酒劲吻你
借酒劲吻你 2020-12-31 14:24

What are the exact steps required for a cookie to persist after a browser is closed? At the moment I have:

  1. createPersistentCookie set to tru
2条回答
  •  甜味超标
    2020-12-31 14:50

    So I found the solution, eventually. As it turns out, it wasn't the problem with the authentication cookie as such (it was retained correctly, or rather would have been if the handler didn't remove it, having incorrectly decided that a user wasn't logged in based on the missing session). The problem was that the Session cookie was lost, or wasn't identified properly. So the fix was to manually add a session cookie during log on like so:

    HttpCookie authCookie = new HttpCookie("ASP.NET_SessionId", Session.SessionID);
    authCookie.Domain = ".mydomain.com";
    authCookie.Expires = DateTime.Now.AddMonths(1);
    Response.Cookies.Add(authCookie);
    

    Now when the browsers opens again the session is identified properly and user session restored.

提交回复
热议问题