public void CreateIdCookie(UserSession session) { var cookieOptions = CreateCookieOptions(); var value = ProtectionUtils.SerializeAndProtect(session.Id, _dataProtector); HttpContext.Response.Cookies.Append(CookieName, value, cookieOptions); }
public Task SetAsync(UserSession userSession) { if (userSession == null) { throw new ArgumentNullException(nameof(userSession)); } var id = userSession.Id; if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentException("Session id is empty."); } var session = ProtectionUtils.SerializeAndProtect(userSession.Data, _dataProtector); return(_distributedCache.SetStringAsync(GetSessionKey(id), session)); }