private void Context_PreRequestHandlerExecute(object sender, EventArgs e) { if (!Configuration.Enabled || !AllowApplicationObject(sender as HttpApplication)) { return; } HttpApplication app = (HttpApplication)sender; HttpContext context = app.Context; if (IsLRAP(context.Request)) { return; } var page = context?.CurrentHandler as Page; var handler = context?.CurrentHandler as IHttpHandler; if (page != null || handler != null) { //https://github.com/snives/HttpModuleRewrite bool requestCallbackExecuted = false; var requestCallback = new Func <string, string>(content => { requestCallbackExecuted = true; var requestForm = content != null ? HttpUtility.ParseQueryString(content) : null; LoggingHelper.SetupSession(context, page, requestForm); LoggingHelper.SetupPage(context, page, page != null ? LogType.OnPageRequest : LogType.OnHandlerRequestReceived, requestForm); if (page != null) { LoggingPage.LogRequest(context, page, requestForm); LoggingPage.LogSession(context, page, requestForm, before: true); } else if (handler != null) { LoggingHandler.LogRequest(context, requestForm); LoggingHandler.LogSession(context, requestForm, before: true); } return(requestForm?.ToString()); }); this.context.Request.Filter = new RequestFilter(this.context.Request.Filter, context.Request.ContentEncoding, requestCallback); if (this.context.Request.Form == null || !requestCallbackExecuted) //Ensure requestCallback is being called to log session and request etc { requestCallback(null); } } }