예제 #1
0
 public void SetSessionData(Session session)
 {
     if (session != null)
     {
         var serializer = new JavaScriptSerializer();
         string jsonSession = serializer.Serialize(session);
         _httpCookies.Set(new HttpCookie(Configuration.CookieName, jsonSession));
     }
 }
예제 #2
0
        public RequestCookieManager(HttpCookieCollection httpCookies)
        {
            try
            {
                _httpCookie = httpCookies[Configuration.CookieName];

                var serializer = new JavaScriptSerializer();
                if (_httpCookie != null && !string.IsNullOrEmpty(_httpCookie.Value))
                    _session = (Session) serializer.Deserialize(_httpCookie.Value, typeof (Session));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, "RequestCookieManager", "Constructor", Severity.Normal);
            }
        }
예제 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         var clientCookie = new RequestCookieManager(Request.Cookies);
         string oldSessionId = clientCookie.GetSessionId();
         var service = new SessionService();
         string newSessionId = service.CreateSession(oldSessionId);
         if (!string.Equals(newSessionId, oldSessionId)) // if its new session then reset cookie.
         {
             var session = new Session { SessionId = newSessionId };
             var cookieManager = new ResponseCookieManager(Response.Cookies);
             cookieManager.SetSessionData(session);
         }
     }
     catch (Exception ex)
     {
         Logger.LogException(ex, "MasterPage", "Page_Load", Severity.Critical);
     }
 }