/// <summary> /// Fills NCache from the system ASP.NET session. /// </summary> /// <param name="cache"></param> /// <param name="session"></param> /// <param name="strict"></param> /// <param name="async"></param> void IDistributionStrategy.FillCacheFromSession(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict, bool isAbandoned) { string sessionId = session.SessionID; SessionKey key = new SessionKey(sessionId, module.ApplicationId); try { if (session.IsReadOnly && cache.Contains(sessionId, key.ToString()) && !isAbandoned) { return; } if (/*session.Count == 0 ||*/ isAbandoned)//[Ata]: Session is not removed from store if it is cleared { cache.Remove(sessionId, key.ToString(), false); if (module.DetailedLogsEnabled) { NSessionStateModule.NCacheLog.Debug(sessionId + " :session removed from cache"); } return; } //use-case: A session my get emptied while doing different updates... although whien added first time is is not empty //So we must update that session rather doing no operation thinking it is empty session and need not to be added. if (session.Count == 0 && _isNewSession) //We need not to keep any new empty session in the cache. [Asif Imam] April 09, 08 { return; } IDictionary ht = new Hashtable(); foreach (string skey in session.Keys) { ht[skey] = session[skey]; } byte[] _stable = CompactBinaryFormatter.ToByteBuffer(ht, module.CacheID); if (_table != null) { if (BinaryComparer(_stable, _table)) { return; } } CacheItem sessionItem = new CacheItem(_stable); sessionItem.Priority = CacheItemPriority.NotRemovable; sessionItem.Expiration = new Runtime.Caching.Expiration(Runtime.Caching.ExpirationType.Sliding, TimeSpan.FromMinutes(session.Timeout)); cache.Insert(sessionId, key.ToString(), sessionItem, false); } finally { if (session != null && strict) { session.Clear(); } } }
public static T Data <T>(SessionKey key) { if (System.Web.HttpContext.Current.Session[key.ToString()] == null) { return(default(T)); } return((T)System.Web.HttpContext.Current.Session[key.ToString()]); }
public static T GetValue <T>(this HttpSessionState sessionState, SessionKey sessionKey) { if (sessionState[sessionKey.ToString()] == null) { return(default(T)); } return((T)sessionState[sessionKey.ToString()]); }
/// <summary> /// Fills NCache from the system ASP.NET session. /// </summary> /// <param name="cache"></param> /// <param name="session"></param> /// <param name="strict"></param> /// <param name="async"></param> void IDistributionStrategy.FillCacheFromSession(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict, bool isAbandoned) { string sessionId = session.SessionID; SessionKey key = new SessionKey(sessionId, module.ApplicationId); try { if (session.IsReadOnly && cache.Contains(sessionId, key.ToString()) && !isAbandoned) { return; } if (isAbandoned)// Session is not removed from store if it is cleared { cache.Remove(sessionId, key.ToString(), false); if (module.DetailedLogsEnabled) { NSessionStateModule.NCacheLog.Debug(sessionId + " :session removed from cache"); } return; } if (session.Count == 0 && _isNewSession) //We need not to keep any new empty session in the cache. { return; } IDictionary ht = new Hashtable(); foreach (string skey in session.Keys) { ht[skey] = session[skey]; } byte[] _stable = CompactBinaryFormatter.ToByteBuffer(ht, module.CacheID); if (_table != null) { if (BinaryComparer(_stable, _table)) { return; } } CacheItem sessionItem = new CacheItem(_stable); sessionItem.Priority = CacheItemPriority.NotRemovable; sessionItem.SlidingExpiration = TimeSpan.FromMinutes(session.Timeout); cache.Insert(sessionId, key.ToString(), sessionItem, false); } finally { if (session != null && strict) { session.Clear(); } } }
public static T GetValue <T>(this HttpSessionStateBase session, SessionKey sessionKey, T value) { if (session[sessionKey.ToString()] == null) { return(value); } return((T)session[sessionKey.ToString()]); }
public static T GetValue <T>(this System.Web.HttpSessionStateBase sessionState, SessionKey sessionKey, T value) { if (sessionState[sessionKey.ToString()] != null) { return((T)sessionState[sessionKey.ToString()]); } else { return(value); } }
public T Get <T>(SessionKey sessionKey, Func <T> func) { var value = _httpContextAccessor.HttpContext.Session.GetString(sessionKey.ToString()); if (value == null) { value = Newtonsoft.Json.JsonConvert.SerializeObject(func()); _httpContextAccessor.HttpContext.Session.SetString(sessionKey.ToString(), value); } return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(_httpContextAccessor.HttpContext.Session.GetString(sessionKey.ToString()).ToString())); }
//private static Boolean IsExpired(SessionKey key) //{ // if (Exists(key)) // { // var cookie = GetCookie(key); // return cookie.Expires < DateTime.Now; // } // return true; //} #endregion #region Delete public static void Delete(SessionKey key) { if (Exists(key)) { var cookie = new HttpCookie(key.ToString()) { Expires = DateTime.Now.AddDays(-1) }; _context.Response.Cookies.Remove(key.ToString()); _context.Response.Cookies.Add(cookie); } }
/// <summary> /// Fills the system ASP.NET session from NCache. /// </summary> /// <param name="session"></param> /// <param name="cache"></param> /// <param name="strict"></param> void IDistributionStrategy.FillSessionFromCache(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict) { string sessionId = session.SessionID; SessionKey key = new SessionKey(sessionId, module.ApplicationId); if (strict) { session.Clear(); } /// save the binary form of data, for comparision on FillCacheFromAspNet() _table = (byte[])cache.Get(key.ToString()); if (_table == null) { _isNewSession = true; return; } Hashtable ht = (Hashtable)CompactBinaryFormatter.FromByteBuffer(_table, module.CacheID); if (ht == null) { return; } IDictionaryEnumerator i = ht.GetEnumerator(); while (i.MoveNext()) { session[i.Key.ToString()] = i.Value; } }
public static HttpCookie GetCookie(SessionKey key) { if (Exists(key)) { return(_context.Request.Cookies.Get(key.ToString())); } return(null); }
public static bool contains(this HttpSessionStateBase session, SessionKey key) { if (session[key.ToString()] != null) { return(true); } return(false); }
public static void Set(SessionKey key, object value) { if (value == null) { value = String.Empty; } var cookie = new HttpCookie(key.ToString()) { Value = value.ToString(), Expires = DateTime.Now.AddHours(1), HttpOnly = true }; _context.Response.Cookies.Remove(key.ToString()); _context.Response.Cookies.Add(cookie); //_context.Response.SetCookie(cookie); }
public T Get <T>(SessionKey sessionKey) { var value = _httpContextAccessor.HttpContext.Session.GetString(sessionKey.ToString()); if (value != null) { return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(_httpContextAccessor.HttpContext.Session.GetString(sessionKey.ToString()))); } return(default(T)); }
/// <summary> /// Fills NCache from the system ASP.NET session. /// </summary> /// <param name="cache"></param> /// <param name="session"></param> /// <param name="strict"></param> /// <param name="async"></param> void IDistributionStrategy.FillCacheFromSession(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict, bool isAbandoned) { if (cache == null) { return; } string sessionId = session.SessionID; SessionKey key = new SessionKey(sessionId, module.ApplicationId); try { if (session.Count == 0) //We need not to keep any empty session in the cache. [Asif Imam] April 09, 08 (This is incomplete. As it is never used. See Monolithic strategy for detail use-case) { return; } cache.Remove(sessionId, key.ToString(), false); cache.Insert(sessionId, key.ToString(), DateTime.Now, Alachisoft.NCache.Runtime.Caching.ExpirationConstants.AbsoluteNoneExpiration, TimeSpan.FromMinutes(session.Timeout), CacheItemPriority.NotRemovable); string[] tempStrArr = new string[1]; tempStrArr[0] = key.ToString(); foreach (string skey in session.Keys) { cache.Insert(sessionId, SessionKey.CompositeKey(sessionId, skey), session[skey], Alachisoft.NCache.Runtime.Caching.ExpirationConstants.AbsoluteNoneExpiration, Alachisoft.NCache.Runtime.Caching.ExpirationConstants.SlidingNoneExpiration, CacheItemPriority.NotRemovable); } if (strict) { session.Clear(); } } catch (Exception exc) { module.RaiseExceptions(exc, "SingleValueDistribution.FillCacheFromSession"); //if (exceptionsEnabled) throw; } }
/// <summary> /// Get session and convert to object /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> public T GetObject <T>(SessionKey key) { try { return(Context.Current.Session.GetObjectFromJson <T>(key.ToString())); } catch { return(default(T)); } }
/// <summary> /// Get session /// </summary> /// <param name="key"></param> /// <returns></returns> public string Get(SessionKey key) { try { return(Context.Current.Session.GetString(key.ToString())); } catch { return(null); } }
//HttpSessionStateBase public static object Get(this HttpSessionStateBase Session, SessionKey Key) { //try //{ return(Get(Session, Key.ToString())); //} //catch(Exception) //{ // return null; //} }
/// <summary> /// Get cookies /// </summary> /// <param name="key"></param> /// <returns></returns> public string Get(SessionKey key) { try { return(Context.Current.Request.Cookies[key.ToString()]); } catch { return(null); } }
internal FirewallSession(FWPM_SESSION0 session) { SessionKey = session.sessionKey; Name = string.IsNullOrEmpty(session.displayData.name) ? SessionKey.ToString() : session.displayData.name; Description = session.displayData.description ?? string.Empty; Flags = session.flags; TxnWaitTimeoutInMSec = session.txnWaitTimeoutInMSec; ProcessId = session.processId; Sid = Sid.Parse(session.sid, false).GetResultOrDefault(); UserName = session.username ?? string.Empty; KernelMode = session.kernelMode; }
/// <summary> /// Set an object /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="expireTime"></param> public void SetObject(SessionKey key, object value, int?expireTime) { CookieOptions option = new CookieOptions(); if (expireTime.HasValue) { option.Expires = DateTime.Now.AddMinutes(expireTime.Value); } else { option.Expires = DateTime.Now.AddMilliseconds(10); } Context.Current.Response.SetObjectAsJson(key.ToString(), value, option); }
public static void Add(SessionKey key, object value) { HttpContext.Current.Session.Add(key.ToString(), value); }
/// <summary> /// Set an object to session /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void SetObject(SessionKey key, object value) { Context.Current.Session.SetObjectAsJson(key.ToString(), value); }
/// <summary> /// Set session /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void Set(SessionKey key, string value) { Context.Current.Session.SetString(key.ToString(), value); }
private static void set(SessionKey sessionKey, HttpSessionState session, object item) { session[sessionKey.ToString()] = item; }
public void Set(SessionKey key, object source) { Session[key.ToString()] = source; }
private static object get(SessionKey sessionKey, HttpSessionState session) { return session[sessionKey.ToString()]; }
public void RemoveSesssion(SessionKey sessionKey) { _httpContextAccessor.HttpContext.Session.Remove(sessionKey.ToString()); }
public static void Remove(SessionKey key) { HttpContext.Current.Session.Remove(key.ToString()); }
public static object Get(SessionKey key) { return(HttpContext.Current.Session[key.ToString()]); }
public static string GetSession(SessionKey key) { return(HttpContext.Current.Session[key.ToString()] == null?string.Empty:HttpContext.Current.Session[key.ToString()].ToString()); }
public object Get(SessionKey key) { return Session[key.ToString()]; }
public static void SetSession(SessionKey key, string value) { HttpContext.Current.Session[key.ToString()] = value; }
public T Set <T>(SessionKey sessionKey, T value) { _httpContextAccessor.HttpContext.Session.SetString(sessionKey.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(value)); return(value); }
public static bool Exists(this HttpSessionStateBase Session, SessionKey Key) { return(Exists(Session, Key.ToString())); }