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 void Module() { // only the ctor requires UnmanagedCode module.Init(app); module.Authenticate += new FormsAuthenticationEventHandler(Authenticate); module.Authenticate -= new FormsAuthenticationEventHandler(Authenticate); module.Dispose(); // but doesn't implement IDisposable }