コード例 #1
0
        public void CreateIdCookie(UserSession session)
        {
            var cookieOptions = CreateCookieOptions();

            var value = ProtectionUtils.SerializeAndProtect(session.Id, _dataProtector);

            HttpContext.Response.Cookies.Append(CookieName, value, cookieOptions);
        }
コード例 #2
0
        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));
        }