Updating forms authentication ticket - weird time

I use Autodesk Forms quite successfully, but ran into some strange problem. I looked through the network and have not found an answer so far.

I use Javascript to determine when the current session is 60 seconds from the timeout, and if so, a pop-up dialog box with a button that, when clicked, will expand the current FormsAuthentication ticket.

This is the code I use to update the ticket. I just add 5 minutes to the current expiration date of the ticket. But when I issue a new expiration date, it is always less than 5 minutes; usually 4 minutes and a few seconds.

Code:

    string userID = HttpContext.Current.User.Identity.Name;
    HttpCookie cookie = FormsAuthentication.GetAuthCookie(userID, true);

    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);

    DateTime NEW_EXPIRY = DateTime.Now.AddMinutes(FormsAuthentication.Timeout.Minutes);

    FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(
        ticket.Version, 
        userID, 
        DateTime.Now,
        NEW_EXPIRY,
        ticket.IsPersistent,
        ticket.UserData,
        ticket.CookiePath);

    cookie.Value = FormsAuthentication.Encrypt(newTicket);

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

    cookie.Secure = FormsAuthentication.RequireSSL;

    HttpContext.Current.Response.Cookies.Add(cookie);

So, here is an example of the derivation of time differences:

= 16/01/2016 14:03:28 = 16/01/2016 14:07:49 (TOTAL SECONDS = 261.0857244)

14:08:28?? ...

+4
1

, , FormsIdentity ... , , ( DateTime) . , , , , .

? , !

0

Source: https://habr.com/ru/post/1624582/


All Articles