private static void CleanupHttpSession(System.Web.HttpApplication context) { // Get a reference to the session module IHttpModule module = context.Modules["Session"]; if (module != null && module.GetType() == typeof(SessionStateModule)) { SessionStateModule stateModule = (SessionStateModule)module; stateModule.Start += (sender, args) => { // Ensure that expired NHibernate sessions are disposed SessionManager.Instance.GetSession(SessionManager.Instance.DefaultSessionKey); SessionEndModule.SessionObjectKey = SessionManager.SessionKeyIdentifier; EventHandler <SessionEndedEventArgs> sessionEndHandler = null; sessionEndHandler = (s, a) => { SessionManager.Instance.DisposeSession((Guid)(a.SessionObject)); SessionEndModule.SessionEnd -= sessionEndHandler; }; SessionEndModule.SessionEnd += sessionEndHandler; }; } }
public void Init(HttpApplication context) { IHttpModule module = context.Modules["Session"]; if (module.GetType() == typeof(SessionStateModule)) { SessionStateModule stateModule = (SessionStateModule)module; stateModule.Start += (Session_Start); } context.BeginRequest += new EventHandler(Application_BeginRequest); }
/// <summary> /// 初始化IdentityCookie模块,并使其为处理请求做好准备。 /// </summary> /// <param name="context">一个 HttpApplication, /// 它提供对 ASP.NET 应用程序内所有应用程序对象的公用的方法、属性和事件的访问。</param> /// <remarks>初始化IdentityCookie模块后, /// 如果发送的请求未包含会话标识符、会话标识符无效或与会话标识符关联的会话已过期, /// 会首先检查是否存在身份Cookie,并根据存在的身份Cookie恢复会话。</remarks> public void Init(HttpApplication context) { IHttpModule module = context.Modules["Session"]; if (module.GetType() == typeof(SessionStateModule)) { SessionStateModule stateModule = (SessionStateModule)module; stateModule.Start += new EventHandler(Session_Start); // SessionStateModule.Start 事件:创建会话时发生的事件。 // 启动新会话后,在请求的初始阶段引发了 Start 事件。 // 如果发送的请求未包含会话标识符、会话标识符无效或与会话标识符关联的会话已过期, // 则会启动新的会话。(而不论是否存在通过编程方式设置的Session对象) } }
public void Init(HttpApplication app) { // Below is an example of how you can handle LogRequest event and provide // custom logging implementation for it //context.PreRequestHandlerExecute += context_PreRequestHandlerExecute; //context.LogRequest += new EventHandler(OnLogRequest); IHttpModule module = app.Modules["Session"]; ///Clarification: "Session" is the name given to the SessionStateModule when it is registered in the root web.config. /// This works by relying on the fact that there's a module in the application's HttpModuleCollection called Session - a fairly safe bet unless you're really messing with the httpModules definition in the .NET Framework's web.config file. Note, however, it could break if a new version of the framework comes along and names the module differently, but it hasn't changed in any of the framework versions that have been released to date. if (module.GetType() == typeof(SessionStateModule)) { SessionStateModule stateModule = (SessionStateModule)module; stateModule.Start += (Session_Start); } }
private static SecurityToken GetSecurityTokenFromWindowsIdentity(WindowsIdentity wi, HttpContext context) { IHttpModule windowsClaimsAuthentication = context.ApplicationInstance.Modules["SPWindowsClaimsAuthentication"]; if (windowsClaimsAuthentication == null) { throw new Exception("Could not find the SPWindowsClaimsAuthentication module"); } MethodInfo getSecurityTokenFromWindowsIdentity = windowsClaimsAuthentication.GetType().GetMethod("GetSecurityTokenFromWindowsIdentity", BindingFlags.NonPublic | BindingFlags.Static); if (getSecurityTokenFromWindowsIdentity == null) { throw new Exception("Could not find the SPWindowsClaimsAuthenticationHttpModule.GetSecurityTokenFromWindowsIdentity method"); } SecurityToken securityToken = (SecurityToken) getSecurityTokenFromWindowsIdentity.Invoke(null, new object[] { wi, context }); return(securityToken); }
/// <summary>Adds Module to the collection of modules.</summary> public void Add(IHttpModule Module) { ExtraModules.Add(Module); ModuleKeys.Add(Module.GetType().Name); }