/// <summary> /// ParseCookies /// </summary> private void ParseCookies() { string httpcookie = this._environment.HttpCookie; if (httpcookie != null) { if (httpcookie.Length > 0) { if (httpcookie.Contains(";")) { string[] cookies = Regex.Split(httpcookie, "; "); for(int x = 0; x < cookies.Length; x++) { string[] cookiesplit = Regex.Split(cookies[x], "="); if (cookiesplit.Length > 1) { Cookie cookie = new Cookie(); cookie.Name = HttpUtility.UrlDecode(cookiesplit[0]); cookie.Value = HttpUtility.UrlDecode(cookiesplit[1]); cookie.Path = "/"; if (!this._cookiejar.Exist(cookie.Name)) { this._cookiejar.Add (cookie); } } } } else { string[] cookiesplit = Regex.Split(httpcookie, "="); if (cookiesplit.Length > 1) { Cookie cookie = new Cookie(); cookie.Name = HttpUtility.UrlDecode(cookiesplit[0]); cookie.Value = HttpUtility.UrlDecode(cookiesplit[1]); cookie.Path = "/"; if (!this._cookiejar.Exist(cookie.Name)) { this._cookiejar.Add (cookie); } } } } } }
public Session(IDictionary<string, string> parameters, byte[] postData) { this._request = new FastCgi.Request (parameters, postData); if (!this._request.CookieJar.Exist ("sorentosessionid")) { this._id = Guid.NewGuid (); FastCgi.Cookie cookie = new FastCgi.Cookie(); cookie.Name = "sorentosessionid"; cookie.Value = this._id.ToString (); cookie.Path = "/"; this._request.CookieJar.Add (cookie); } else { bool expired = false; try { Session session = Session.Load (new Guid (this._request.CookieJar.Get ("sorentosessionid").Value)); this._id = session.Id; this._createtimestamp = session._createtimestamp; this._user = session._user; if ((Date.DateTimeToTimestamp (DateTime.Now) - session._updatetimestamp) > Services.Config.Get<int> (Enums.ConfigKey.core_sessiontimeout) || session._remoteaddress != this._request.Environment.RemoteAddress) { expired = true; } } catch (Exception exception) { // LOG: LogDebug.ExceptionUnknown Services.Logging.LogDebug (string.Format (Strings.LogDebug.ExceptionUnknown, "SORENTOLIB.SESSION", exception.Message)); expired = true; } if (expired) { Services.Logging.LogDebug (string.Format (Strings.LogDebug.SessionTimeout, this._request.CookieJar.Get ("sorentosessionid").Value)); this._id = Guid.NewGuid (); this._createtimestamp = Date.CurrentDateTimeToTimestamp (); this._user = null; this._request.CookieJar.Get ("sorentosessionid").Value = this._id.ToString (); } } if (this._user != null) { if (this._user.Status == Enums.UserStatus.Disabled) { this._user = null; } } this._remoteaddress = this._request.Environment.RemoteAddress; // Fill accepted languages. this._languages = new List<string> (); foreach (string language in this._request.Environment.HttpAcceptLanguage.Split (";".ToCharArray ())[0].ToString ().Split (",".ToCharArray ())) { this._languages.Add (language); } this._timeout = Services.Config.Get<int> (Enums.ConfigKey.core_sessiontimeout); this._page = new Page (this._request.Environment.HttpHost); this._error = new Error (); this.Save (); }