public HttpSessionState UpdateContext (HttpContext context, SessionStateModule module, bool required, bool read_only, ref bool isNew) { if (!required) return null; Cache cache = HttpRuntime.Cache; HttpSessionState state = null; string id = SessionId.Lookup (context.Request, config.CookieLess); if (id != null) { state = (HttpSessionState) cache ["@@@InProc@" + id]; if (state != null) return state; } // Create a new session. string sessionID = SessionId.Create (module.Rng); state = new HttpSessionState (sessionID, // unique identifier new SessionDictionary(), // dictionary HttpApplicationFactory.ApplicationState.SessionObjects, config.Timeout, //lifetime before death. true, //new session false, // is cookieless SessionStateMode.InProc, read_only); //readonly TimeSpan timeout = new TimeSpan (0, config.Timeout, 0); cache.InsertPrivate ("@@@InProc@" + sessionID, state, null, DateTime.Now + timeout, timeout, CacheItemPriority.AboveNormal, removedCB); isNew = true; return state; }
public void Init (SessionStateModule module, HttpApplication context, SessionConfig config) { string connectionTypeName; string providerAssemblyName; string cncString; this.config = config; GetConnectionData (out providerAssemblyName, out connectionTypeName, out cncString); if (cncType == null) { Assembly dbAssembly = Assembly.Load (providerAssemblyName); cncType = dbAssembly.GetType (connectionTypeName, true); if (!typeof (IDbConnection).IsAssignableFrom (cncType)) throw new ApplicationException ("The type '" + cncType + "' does not implement IDB Connection.\n" + "Check 'DbConnectionType' in server.exe.config."); } cnc = (IDbConnection) Activator.CreateInstance (cncType); cnc.ConnectionString = cncString; try { cnc.Open (); } catch (Exception exc) { cnc = null; throw exc; } }
public void UpdateHandler (HttpContext context, SessionStateModule module) { HttpSessionState session = context.Session; if (session == null || session.IsReadOnly || !session._abandoned) return; HttpRuntime.Cache.Remove ("@@@InProc@" + session.SessionID); }
public void Init (SessionStateModule module, HttpApplication context, SessionConfig config) { this.config = config; RemotingConfiguration.Configure (null); string cons, proto, server, port; GetConData (config.StateConnectionString, out proto, out server, out port); cons = String.Format ("{0}://{1}:{2}/StateServer", proto, server, port); state_server = (RemoteStateServer) Activator.GetObject (typeof (RemoteStateServer), cons); }
public ActionResult Login(int?id) { //Session.Abandon(); SessionIDManager manager = new SessionIDManager(); manager.RemoveSessionID(System.Web.HttpContext.Current); var oldId = manager.GetSessionID(System.Web.HttpContext.Current); var newId = manager.CreateSessionID(System.Web.HttpContext.Current); var isRedirected = true; var isAdded = true; manager.SaveSessionID(System.Web.HttpContext.Current, newId, out isRedirected, out isAdded); System.Web.HttpContext.Current.Session["sessionid"] = newId; HttpApplication ctx = (HttpApplication)System.Web.HttpContext.Current.ApplicationInstance; HttpModuleCollection mods = ctx.Modules; System.Web.SessionState.SessionStateModule ssm = (SessionStateModule)mods.Get("Session"); System.Reflection.FieldInfo[] fields = ssm.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance); SessionStateStoreProviderBase store = null; System.Reflection.FieldInfo rqIdField = null, rqLockIdField = null, rqStateNotFoundField = null; foreach (System.Reflection.FieldInfo field in fields) { if (field.Name.Equals("_store")) { store = (SessionStateStoreProviderBase)field.GetValue(ssm); } if (field.Name.Equals("_rqId")) { rqIdField = field; } if (field.Name.Equals("_rqLockId")) { rqLockIdField = field; } if (field.Name.Equals("_rqSessionStateNotFound")) { rqStateNotFoundField = field; } } object lockId = rqLockIdField.GetValue(ssm); if ((lockId != null) && (oldId != null)) { store.ReleaseItemExclusive(System.Web.HttpContext.Current, oldId, lockId); } rqStateNotFoundField.SetValue(ssm, true); rqIdField.SetValue(ssm, newId); ViewBag.CompanyID = id; ViewBag.Message = id.HasValue ? "" : "缺少公司标识"; ViewBag.ThirdLoginUrl = string.Format("{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code", authorizeUrl, clinetId, redirectUri, state); return(View()); }
internal HttpSessionStateContainer(SessionStateModule stateModule, string id, ISessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout, bool newSession, HttpCookieMode cookieMode, SessionStateMode mode, bool isReadonly) { this._stateModule = stateModule; this._id = id; this._sessionItems = sessionItems; this._staticObjects = staticObjects; this._timeout = timeout; this._newSession = newSession; this._cookieMode = cookieMode; this._mode = mode; this._isReadonly = isReadonly; }
public void UpdateHandler (HttpContext context, SessionStateModule module) { HttpSessionState session = context.Session; if (session == null || session.IsReadOnly) return; string id = session.SessionID; if (!session._abandoned) { SessionDictionary dict = session.SessionDictionary; UpdateSession (id, dict); } else { DeleteSession (id); } }
public void UpdateHandler (HttpContext context, SessionStateModule module) { HttpSessionState session = context.Session; if (session == null || session.IsReadOnly) return; string id = session.SessionID; if (!session._abandoned) { SessionDictionary dict = session.SessionDictionary; HttpStaticObjectsCollection sobjs = session.StaticObjects; state_server.Update (id, dict.ToByteArray (), sobjs.ToByteArray ()); } else { state_server.Remove (id); } }
private void RegenerateSessionId() { var Context = System.Web.HttpContext.Current; System.Web.SessionState.SessionIDManager manager = new System.Web.SessionState.SessionIDManager(); string oldId = manager.GetSessionID(Context); string newId = manager.CreateSessionID(Context); bool isAdd = false, isRedir = false; manager.SaveSessionID(Context, newId, out isRedir, out isAdd); HttpApplication ctx = Context.ApplicationInstance; HttpModuleCollection mods = ctx.Modules; System.Web.SessionState.SessionStateModule ssm = (SessionStateModule)mods.Get("Session"); System.Reflection.FieldInfo[] fields = ssm.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance); SessionStateStoreProviderBase store = null; System.Reflection.FieldInfo rqIdField = null, rqLockIdField = null, rqStateNotFoundField = null; foreach (System.Reflection.FieldInfo field in fields) { if (field.Name.Equals("_store")) { store = (SessionStateStoreProviderBase)field.GetValue(ssm); } if (field.Name.Equals("_rqId")) { rqIdField = field; } if (field.Name.Equals("_rqLockId")) { rqLockIdField = field; } if (field.Name.Equals("_rqSessionStateNotFound")) { rqStateNotFoundField = field; } } object lockId = rqLockIdField.GetValue(ssm); if ((lockId != null) && (oldId != null)) { store.ReleaseItemExclusive(Context, oldId, lockId); } rqStateNotFoundField.SetValue(ssm, true); rqIdField.SetValue(ssm, newId); }
public void Init(HttpApplication context) { context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute); for (int i = 0; i < context.Modules.Count; i++) { if (context.Modules[i] is SessionStateModule) { _SessionModule = (SessionStateModule)context.Modules[i]; break; } } if (_SessionModule != null) { _SessionModule.Start += new EventHandler(SessionModule_Start); //_SessionModule.End += new EventHandler(SessionModule_End); // doesn't work } }
internal HttpSessionStateContainer( SessionStateModule stateModule, string id, ISessionStateItemCollection sessionItems, HttpStaticObjectsCollection staticObjects, int timeout, bool newSession, HttpCookieMode cookieMode, SessionStateMode mode, bool isReadonly) { _stateModule = stateModule; _id = id; // If null, it means we're delaying session id reading _sessionItems = sessionItems; _staticObjects = staticObjects; _timeout = timeout; _newSession = newSession; _cookieMode = cookieMode; _mode = mode; _isReadonly = isReadonly; }
public HttpSessionState UpdateContext(HttpContext context, SessionStateModule module, bool required, bool read_only, ref bool isNew) { if (!required) { return(null); } Cache cache = HttpRuntime.InternalCache; HttpSessionState state = null; string id = SessionId.Lookup(context.Request, config.CookieLess); if (id != null) { state = (HttpSessionState)cache ["@@@InProc@" + id]; if (state != null) { return(state); } } // Create a new session. string sessionID = SessionId.Create(); state = new HttpSessionState(sessionID, // unique identifier new SessionDictionary(), // dictionary HttpApplicationFactory.ApplicationState.SessionObjects, config.Timeout, //lifetime before death. true, //new session false, // is cookieless SessionStateMode.InProc, read_only); //readonly TimeSpan timeout = new TimeSpan(0, config.Timeout, 0); cache.Insert(INPROC_CACHE_PREFIX + sessionID, state, null, Cache.NoAbsoluteExpiration, timeout, CacheItemPriority.AboveNormal, removedCB); isNew = true; return(state); }
public void UpdateHandler(HttpContext context, SessionStateModule module) { HttpSessionState session = context.Session; if (session == null || session.IsReadOnly) { return; } string id = session.SessionID; if (!session._abandoned) { SessionDictionary dict = session.SessionDictionary; UpdateSessionWithRetry(id, session.Timeout, dict); } else { DeleteSessionWithRetry(id); } }
public void Init(SessionStateModule module, HttpApplication context, SessionConfig config) { this.config = config; this.AppPath = context.Request.ApplicationPath; try { InitializeConnection(); } catch (Exception exc) { cnc = null; throw exc; } if (paramPrefix != defaultParamPrefix) { ReplaceParamPrefix(ref selectCommandText); ReplaceParamPrefix(ref insertCommandText); ReplaceParamPrefix(ref updateCommandText); ReplaceParamPrefix(ref deleteCommandText); } }
public HttpSessionState UpdateContext (HttpContext context, SessionStateModule module, bool required, bool read_only, ref bool isNew) { if (!required) return null; StateServerItem item = null; HttpSessionState session = null; SessionDictionary dict = null; HttpStaticObjectsCollection sobjs = null; string id = GetId (context); if (id != null) { item = state_server.Get (id); if (item != null) { dict = SessionDictionary.FromByteArray (item.DictionaryData); sobjs = HttpStaticObjectsCollection.FromByteArray (item.StaticObjectsData); session = new HttpSessionState (id, dict, HttpApplicationFactory.ApplicationState.SessionObjects, config.Timeout, false, config.CookieLess, SessionStateMode.StateServer, read_only); return session; } } id = SessionId.Create (module.Rng); dict = new SessionDictionary (); sobjs = HttpApplicationFactory.ApplicationState.SessionObjects; item = new StateServerItem (dict.ToByteArray (), sobjs.ToByteArray (), config.Timeout); state_server.Insert (id, item); session = new HttpSessionState (id, dict, sobjs, config.Timeout, true, config.CookieLess, SessionStateMode.StateServer, read_only); isNew = true; return session; }
public void Init (SessionStateModule module, HttpApplication context, SessionConfig config) { this.config = config; this.AppPath = context.Request.ApplicationPath; try { InitializeConnection (); } catch (Exception exc) { cnc = null; throw exc; } if (paramPrefix != defaultParamPrefix) { ReplaceParamPrefix (ref selectCommandText); ReplaceParamPrefix (ref insertCommandText); ReplaceParamPrefix (ref updateCommandText); ReplaceParamPrefix (ref deleteCommandText); } }
private void OneTimeInit() { SessionStateSection sessionState = RuntimeConfig.GetAppConfig().SessionState; s_configPartitionResolverType = sessionState.PartitionResolverType; s_configStateConnectionString = sessionState.StateConnectionString; s_configStateConnectionStringFileName = sessionState.ElementInformation.Properties["stateConnectionString"].Source; s_configStateConnectionStringLineNumber = sessionState.ElementInformation.Properties["stateConnectionString"].LineNumber; s_configCompressionEnabled = sessionState.CompressionEnabled; if (this._partitionResolver == null) { string stateConnectionString = sessionState.StateConnectionString; SessionStateModule.ReadConnectionString(sessionState, ref stateConnectionString, "stateConnectionString"); s_singlePartitionInfo = (StateServerPartitionInfo)this.CreatePartitionInfo(stateConnectionString); } else { s_usePartition = true; s_partitionManager = new PartitionManager(new System.Web.CreatePartitionInfo(this.CreatePartitionInfo)); } s_networkTimeout = (int)sessionState.StateNetworkTimeout.TotalSeconds; string appDomainAppIdInternal = HttpRuntime.AppDomainAppIdInternal; string str3 = MachineKeySection.HashAndBase64EncodeString(appDomainAppIdInternal); if (appDomainAppIdInternal.StartsWith("/", StringComparison.Ordinal)) { s_uribase = appDomainAppIdInternal + "(" + str3 + ")/"; } else { s_uribase = "/" + appDomainAppIdInternal + "(" + str3 + ")/"; } s_onAppDomainUnload = new EventHandler(this.OnAppDomainUnload); Thread.GetDomain().DomainUnload += s_onAppDomainUnload; s_oneTimeInited = true; }
static internal void AddHttpSessionStateModuleToContext(HttpContext context, SessionStateModule module, bool delayed) { context.AddHttpSessionStateModule(module, delayed); }
internal void AddDelayedHttpSessionState(SessionStateModule module) { if (_sessionStateModule != null) { throw new HttpException(SR.GetString(SR.Cant_have_multiple_session_module)); } _sessionStateModule = module; }
public void FixtureSetUp () { app = new HttpApplication (); module = new SessionStateModule (); }
public void Init(SessionStateModule module, HttpApplication context, #if NET_2_0 SessionStateSection config
static internal void AddDelayedHttpSessionStateToContext(HttpContext context, SessionStateModule module) { context.AddDelayedHttpSessionState(module); }
public void Init (SessionStateModule module, HttpApplication context, SessionConfig config) { removedCB = new CacheItemRemovedCallback (module.OnSessionRemoved); this.config = config; }
internal void RemoveDelayedHttpSessionState() { this._sessionStateModule = null; }
internal void AddHttpSessionStateModule(SessionStateModule module, bool delayed) { if (_sessionStateModule != null && _sessionStateModule != module) { throw new HttpException(SR.GetString(SR.Cant_have_multiple_session_module)); } _sessionStateModule = module; _delayedSessionState = delayed; }
internal void RemoveDelayedHttpSessionState() { Debug.Assert(_sessionStateModule != null, "_sessionStateModule != null"); _sessionStateModule = null; }
void IStateClientManager.SetStateModule(SessionStateModule module) { }
public HttpSessionState UpdateContext (HttpContext context, SessionStateModule module, bool required, bool read_only, ref bool isNew) { if (!required) return null; HttpSessionState session = null; string id = SessionId.Lookup (context.Request, config.CookieLess); if (id != null) { session = SelectSession (id, read_only); if (session != null) return session; } id = SessionId.Create (); session = new HttpSessionState (id, new SessionDictionary (), HttpApplicationFactory.ApplicationState.SessionObjects, config.Timeout, true, config.CookieLess, SessionStateMode.SQLServer, read_only); InsertSessionWithRetry (session, config.Timeout); isNew = true; return session; }
internal static void AddDelayedHttpSessionStateToContext(HttpContext context, SessionStateModule module) { context.AddDelayedHttpSessionState(module); }
internal void SetModule(SessionStateModule module) { _module = module; }
internal void RemoveHttpSessionStateModule() { Debug.Assert(_sessionStateModule != null, "_sessionStateModule != null"); _delayedSessionState = false; _sessionStateModule = null; }
internal void RemoveHttpSessionStateModule() { _delayedSessionState = false; _sessionStateModule = null; }
private static void HookSessionEvent(SessionStateModule sessionStateModule) { // Hook only into InProcState - all others ignore SessionEnd anyway object store = ExpressionEvaluator.GetValue(sessionStateModule, "_store"); if ((store != null) && store.GetType().Name == "InProcSessionStateStore") { s_log.Debug("attaching to InProcSessionStateStore"); s_originalCallback = (CacheItemRemovedCallback)ExpressionEvaluator.GetValue(store, "_callback"); ExpressionEvaluator.SetValue(store, "_callback", new CacheItemRemovedCallback(OnCacheItemRemoved)); CACHEKEYPREFIXLENGTH = (int)ExpressionEvaluator.GetValue(store, "CACHEKEYPREFIXLENGTH"); } }
public void Init(SessionStateModule module, HttpApplication context, SessionConfig config) { removedCB = new CacheItemRemovedCallback(module.OnSessionRemoved); this.config = config; }
internal void AddDelayedHttpSessionState(SessionStateModule module) { if (this._sessionStateModule != null) { throw new HttpException(System.Web.SR.GetString("Cant_have_multiple_session_module")); } this._sessionStateModule = module; }