Decrypting a cookie converts it to local time?

I have my own asp.net cookie created like this:

var authTicket = new FormsAuthenticationTicket(
    version,
    userName,
    DateTime.UtcNow,
    DateTime.UtcNow.AddMinutes(30),
    createPersistentCookie,
    userData,
    "/");

string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

As you can see, all the time UTC.

When I decrypt it:

var cookie = HttpContext.Current.Request.Cookies.Get(FormsAuthentication.FormsCookieName);

if (cookie != null)
{
    var ticket = FormsAuthentication.Decrypt(cookie.Value);
    return ticket.Expiration.Ticks;
}
else
{
    return 0;
}

Returns the local time. So does it convert automatically or is it something else? If so, how can I return it to UTC?

+3
source share
2 answers

From MSDN :

Property FormsAuthenticationTicket.Expiration

Gets the local date and time at which the authentication form expires.

DateTime.ToUniversalTime DateTime UTC:

return ticket.Expiration.ToUniversalTime().Ticks;
+3

, FormsAuthenticationTicket cookie , .

"" MSDN : " FormsAuthenticationTicket , , , expiration.". , UTC, UTC , /, .

issueDate , . - , .NET 1.x.

.NET 1.x DateTime "", , UTC - .

, FormsAuthenticationTicket, , Microsoft Connect.

0

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


All Articles