コード例 #1
0
        private void SetCLIENTTokenInSession(int userId)
        {
            string clientTokenValue;

            //SessionCacheData sessionCacheData = WebApiApplication.SessionCacheService.Get(userName);
            //if (sessionCacheData != null && !string.IsNullOrWhiteSpace(sessionCacheData.XCSRFTokenValue))
            //{
            //    clientTokenValue = sessionCacheData.XCSRFTokenValue;
            //}
            //else
            //{
            clientTokenValue = Guid.NewGuid().ToString();
            //}
            //SessionDataProvider.SetXCSRFToken(xcsrfTokenValue);
            var httpContextWrapper = GetHttpContextWrapper();


            HttpCookie clientToken = new HttpCookie(WebApiApplication.CLIENT_Token, clientTokenValue);

            HttpContext.Current.Response.Cookies.Add(clientToken);
            UserSession userSession = new UserSession();

            userSession.UserId       = userId;
            userSession.UserToken    = clientTokenValue;
            userSession.LastPingTime = DateTime.Now;
            userSession.MachineName  = httpContextWrapper.Request.UserHostName;
            UserSessionService userSessionService = new UserSessionService();

            userSessionService.AddSession(userSession);

            //HttpContext.Current.Session.Contents.Add(WebApiApplication.CLIENT_Token, clientTokenValue);
            //HttpContext.Current.Session.Add(WebApiApplication.CLIENT_Token, clientTokenValue);
        }