public void Init(HttpApplication context) { _formsAuthenticationModule = new FormsAuthenticationModule(); // используется блок try-catch, так как при инициализации _formsAuthenticationModule могут возникнуть всякие exception'ы (например, при попытке его подцепиться ко всяким событиям application'а, context'а или request'а). try { using (HttpApplication fakeApplication = new HttpApplication()) { _formsAuthenticationModule.Init(fakeApplication); } } catch (Exception) { } // using reflection - need FULL TRUST Type t = _formsAuthenticationModule.GetType(); _formsAuthenticationModuleOnEnter = t.GetMethod("OnEnter", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Object), typeof(EventArgs) }, null); _formsAuthenticationModuleOnLeave = t.GetMethod("OnLeave", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Object), typeof(EventArgs) }, null); if (_formsAuthenticationModuleOnEnter == null || _formsAuthenticationModuleOnLeave == null) throw new Exception("Unable to get all required FormsAuthenticationModule entrypoints using reflection."); context.AuthenticateRequest += new EventHandler(OnAuthenticateRequest); context.PostAuthenticateRequest += new EventHandler(OnPostAuthenticateRequest); context.EndRequest += new EventHandler(OnEndRequest); }
public FormsAuthenticationModuleWrapper(FormsAuthenticationModule formsAuthenticationModule) { if(formsAuthenticationModule == null) throw new ArgumentNullException("formsAuthenticationModule"); this._formsAuthenticationModule = formsAuthenticationModule; this._formsAuthenticationModule.Authenticate += this.OnFormsAuthenticationModuleAuthenticate; }
public void Init(HttpApplication app) { // Create the real FormsAuthenticationModule to which we will delegate _module = new System.Web.Security.FormsAuthenticationModule(); // This may throw an exception when trying to register the module // event handlers. This exception is expected and doesnt affect // the operation. However, catching this exception here is // a poor practice because it may hide other exceptions. try { using (HttpApplication dummy = new HttpApplication()) { _module.Init(dummy); } } catch (Exception e) { } // Get the methods on it (private) using private reflection // NOTE: this requires full trust Type t = _module.GetType(); _onEnter = t.GetMethod( "OnEnter", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Object), typeof(EventArgs) }, null ); _onLeave = t.GetMethod( "OnLeave", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Object), typeof(EventArgs) }, null ); if (_onEnter == null || _onLeave == null) { throw new Exception("Unable to get all required FormsAuthenticationModule entrypoints using reflection."); } // Register for the required notifications app.AuthenticateRequest += new EventHandler(OnAuthenticateRequest); app.PostAuthenticateRequest += new EventHandler(OnPostAuthenticateRequest); app.EndRequest += new EventHandler(OnEndRequest); }
public void Dispose() { _module.Dispose(); _module = null; GC.SuppressFinalize(this); }
public void FixtureSetUp () { app = new HttpApplication (); module = new FormsAuthenticationModule (); }
void OnEndRequest(object sender, EventArgs e) { //DebugThis("begin:" + HttpContext.Current.Response.StatusCode.ToString()); HttpApplication application = sender as HttpApplication; string authType = application.Context.Items["AuthType"] as string; if (authType == "Forms") { FormsAuthenticationModule formsAuthenticationModule = new FormsAuthenticationModule(); MethodInfo formsAuthenticationModuleOnEnterMethodInfo = formsAuthenticationModule.GetType().GetMethod("OnLeave", BindingFlags.Instance | BindingFlags.NonPublic); formsAuthenticationModuleOnEnterMethodInfo.Invoke( formsAuthenticationModule, new object[] { sender, e }); } Logger.WriteVerbose("PortalAuthenticationModule.OnEndRequest", new Dictionary<string, object> { { "Url", HttpContext.Current.Request.Url }, { "StatusCode", HttpContext.Current.Response.StatusCode } }); }
private static void CallInternalOnEnter(object sender, EventArgs e) { FormsAuthenticationModule formsAuthenticationModule = new FormsAuthenticationModule(); MethodInfo formsAuthenticationModuleOnEnterMethodInfo = formsAuthenticationModule.GetType().GetMethod("OnEnter", BindingFlags.Instance | BindingFlags.NonPublic); formsAuthenticationModuleOnEnterMethodInfo.Invoke( formsAuthenticationModule, new object[] { sender, e }); }
public void Dispose() { _formsAuthenticationModule.Dispose(); _formsAuthenticationModule = null; GC.SuppressFinalize(this); }