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); }
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 }); }
private void OnEndRequest(object sender, EventArgs e) { 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 }); } SnTrace.Web.Write("PortalAuthenticationModule.OnEndRequest. Url:{0}, StatusCode:{1}", HttpContext.Current.Request.Url, HttpContext.Current.Response.StatusCode); }
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 } }); }