private void Filter(ExceptionFilterEventArgs e) { var exception = e.Exception.GetBaseException(); var httpException = exception as HttpException; if (HttpContext.Current.Request.IsLocal) { e.Dismiss(); return; } // User hit stop/esc while the page was posting back if (exception is HttpException && exception.Message.ToLower().Contains("the client disconnected.") || exception.Message.ToLower().Contains("the remote host closed the connection.")) { e.Dismiss(); return; } // User hit stop while posting back and thew this error if (exception is ViewStateException && exception.Message.ToLower().Contains("invalid viewstate. client ip:")) { e.Dismiss(); return; } }
void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs args) { if (args.Exception is ArgumentException) { args.Dismiss(); return; } var context = (HttpContext)args.Context; if (context != null && context.Request.UserAgent != null) { if (context.Request.UserAgent == "Test Certificate Info" && args.Exception is System.Web.HttpException) { args.Dismiss(); return; } if (context.Request.UserAgent.Contains("ZmEu")) { args.Dismiss(); return; } if (context.Request.UserAgent.Contains("Googlebot")) { args.Dismiss(); return; } } Filter(args); }
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e) { if (e.Exception.GetBaseException() is HttpException && ((HttpException)e.Exception.GetBaseException()).GetHttpCode() == 404) { e.Dismiss(); } }
private void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e) { if (e.Exception is System.Threading.ThreadAbortException) { e.Dismiss(); } }
//private static IWindsorContainer InitializeServiceLocator() //{ // //IWindsorContainer container = new WindsorContainer(); // //ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); // //container.RegisterControllers(typeof(HomeController).Assembly); // //ComponentRegistrar.AddComponentsTo(container); // //ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container)); // //return container; //} /// <summary> /// ELMAH filtering for the mail log /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e) { if (e.Exception.GetBaseException() is HttpException) { e.Dismiss(); } }
protected virtual void OnErrorModuleFiltering(object sender, ExceptionFilterEventArgs args) { if (args == null) { throw new ArgumentNullException("args"); } if (args.Exception == null) { throw new ArgumentException(null, "args"); } try { if (Assertion.Test(new AssertionHelperContext(sender, args.Exception, args.Context))) { args.Dismiss(); } } catch (Exception e) { Trace.WriteLine(e); throw; } }
public void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e) { var httpException = e.Exception as HttpException; if (httpException != null && httpException.GetHttpCode() == 404 || Debugger.IsAttached) { e.Dismiss(); } }
public void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e) { var httpException = e.Exception as JavaScriptException; if (httpException != null) { e.Dismiss(); } }
private void Filter404Errors(ExceptionFilterEventArgs args) { if (args.Exception.GetBaseException() is HttpException) { var httpException = args.Exception.GetBaseException() as HttpException; if (httpException != null && httpException.GetHttpCode() == 404) args.Dismiss(); } }
/// <summary> /// Raises the <see cref="Filtering"/> event. /// </summary> protected virtual void OnFiltering(ExceptionFilterEventArgs args) { ExceptionFilterEventHandler handler = Filtering; if (handler != null) { handler(this, args); } }
/// <summary> /// Logs an exception and its context to the error log. /// </summary> protected virtual void LogException(Exception e, HttpContextBase context) { if (e == null) { throw new ArgumentNullException("e"); } // // Fire an event to check if listeners want to filter out // logging of the uncaught exception. // ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) { return; } // // Log away... // ErrorLogEntry entry = null; try { Error error = new Error(e, context); ErrorLog log = GetErrorLog(context); error.ApplicationName = log.ApplicationName; OnLogging(new ErrorLoggingEventArgs(error)); string id = log.Log(error); entry = new ErrorLogEntry(log, id, error); } catch (Exception localException) { // // IMPORTANT! We swallow any exception raised during the // logging and send them out to the trace . The idea // here is that logging of exceptions by itself should not // be critical to the overall operation of the application. // The bad thing is that we catch ANY kind of exception, // even system ones and potentially let them slip by. // Trace.WriteLine(localException); } if (entry != null) { OnLogged(new ErrorLoggedEventArgs(entry)); } }
// Dismiss 404 errors for ELMAH private void FilterError404(ExceptionFilterEventArgs e) { if (e.Exception.GetBaseException() is HttpException) { HttpException ex = (HttpException)e.Exception.GetBaseException(); if (ex.GetHttpCode() == 404) e.Dismiss(); } }
// Dismiss 404 errors for ELMAH private static void FilterError404(ExceptionFilterEventArgs e) { if (!(e.Exception.GetBaseException() is HttpException)) { return; } var ex = (HttpException)e.Exception.GetBaseException(); if (ex.GetHttpCode() == 404) e.Dismiss(); }
// Dismiss 404 errors for ELMAH private void FilterError404(ExceptionFilterEventArgs e) { if (e.Exception.GetBaseException() is HttpException) { HttpException ex = (HttpException)e.Exception.GetBaseException(); if (ex.GetHttpCode() == 404) e.Dismiss(); } // Response.Redirect(@"/Error/Trouble"); }
public void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e) { var httpException = e.Exception as HttpException; if (httpException != null && httpException.GetHttpCode() == 404) { e.Dismiss(); } #if DEBUG e.Dismiss(); #endif }
/// <summary> /// This method checks the HttpContext associated with the Exception for any sensitive /// data submitted in the form that should not be logged in plain text. /// If fields are found that match the names in the SensitiveFieldNames list, their values /// are replaced with **** before the error is logged. /// </summary> /// <param name="args"></param> internal static void FilterSensitiveData(ExceptionFilterEventArgs args) { if (args.Context != null) { HttpContext context = (HttpContext)args.Context; if (context.Request != null && context.Request.Form != null && context.Request.Form.AllKeys.Intersect(sensitiveFieldNames, StringComparer.InvariantCultureIgnoreCase).Any()) { ReplaceSensitiveFormFields(args, context); } } }
private static void ReplaceSensitiveFormFields(ExceptionFilterEventArgs args, HttpContext context) { var replacementError = new Error(args.Exception, (HttpContext)args.Context); foreach (var formField in context.Request.Form.AllKeys) { if (sensitiveFieldNames.Contains(formField, StringComparer.InvariantCultureIgnoreCase)) { replacementError.Form.Set(formField, "****"); } } ErrorLog.GetDefault(HttpContext.Current).Log(replacementError); args.Dismiss(); }
protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e) { // Cancels elmah logging for these conditions. //if (!Request.Url.ToString().ToLower().Contains(ConfigurationManager.AppSettings["klasresearchURL"], true) || Request.UserAgent.ToLower().Contains("bot", true) || Request.UserAgent.ToLower().Contains("spider", true) || Request.UserAgent.ToLower().Contains("crawler", true) || Request.UserAgent.ToLower().Contains("slurp", true) || Request.UserAgent.ToLower().Contains("ezooms", true)) //{ // e.Dismiss(); //} //if (Request.Url.ToString().ToLower().Contains("jw-icons.eot")) //{ // e.Dismiss(); //} }
public void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e) { var ex = e.Exception.GetBaseException(); var httpex = ex as HttpException; if (httpex != null) { var status = httpex.GetHttpCode(); if (status == 400 || status == 404) e.Dismiss(); else if (httpex.Message.Contains("The remote host closed the connection")) e.Dismiss(); else if (httpex.Message.Contains("A potentially dangerous Request.Path value was detected from the client")) e.Dismiss(); } if (ex is FileNotFoundException || ex is HttpRequestValidationException) e.Dismiss(); }
protected virtual void OnErrorModuleFiltering(object sender, ExceptionFilterEventArgs args) { if (args == null) throw new ArgumentNullException("args"); if (args.Exception == null) throw new ArgumentException(null, "args"); try { if (Assertion.Test(new AssertionHelperContext(sender, args.Exception, args.Context))) args.Dismiss(); } catch (Exception e) { Trace.WriteLine(e); throw; } }
protected override void LogException(Exception e, HttpContext context) { if (e == null) throw new ArgumentNullException("e"); var args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) return; try { e.SendToAirbrake(); } catch (Exception localException) { Trace.WriteLine(localException); } }
/// <summary> /// Reports the exception. /// </summary> protected virtual void OnError(Exception e, HttpContext context) { if (e == null) { throw new ArgumentNullException("e"); } // Fire an event to check if listeners want to filter out reporting of the uncaught exception. Elmah.ExceptionFilterEventArgs args = new Elmah.ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) { return; } // Get the last error and then write it to the EventLog. Elmah.Error error = new Elmah.Error(e, context); ReportError(error); }
private static void FilterException(object sender, ExceptionFilterEventArgs args) { var httpContext = args.Context as HttpContext; var error = new Error(args.Exception, httpContext.ApplicationInstance.Context); var sensitiveFormDataNames = httpContext.Items[Constants.HttpContextItemsKey] as IEnumerable<string>; if (sensitiveFormDataNames == null) { return; } var sensitiveFormData = httpContext.Request.Form.AllKeys .Where(key => sensitiveFormDataNames.Contains(key.ToLowerInvariant())) .ToList(); if (sensitiveFormData.Any()) { sensitiveFormData.ForEach(k => error.Form.Set(k, Config.SensitiveDataReplacementText)); ErrorLog.GetDefault(httpContext).Log(error); args.Dismiss(); } }
/// <summary> /// Reports the exception. /// </summary> protected virtual void OnError(Exception e, HttpContext context) { if (e == null) { throw new ArgumentNullException("e"); } // // Fire an event to check if listeners want to filter out // reporting of the uncaught exception. // ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) { return; } // // Get the last error and then report it synchronously or // asynchronously based on the configuration. // Error error = new Error(e, context); if (_reportAsynchronously) { ReportErrorAsync(error); } else { ReportError(error); } }
//Dimiss 404 errors for ELMAH protected void FilterError(ExceptionFilterEventArgs e) { if (e.Exception.GetBaseException() is HttpException) { HttpException ex = (HttpException)e.Exception.GetBaseException(); if (ex.Message.Contains("A potentially dangerous Request.Path value was detected from the client")) e.Dismiss(); else { switch (ex.GetHttpCode()) { case 404: e.Dismiss(); break; case 410: e.Dismiss(); break; case 406: e.Dismiss(); break; } } } }
private static void FilterOutSensitiveFormData(ExceptionFilterEventArgs e) { var ctx = e.Context as HttpContext; if (ctx == null) return; var sensitiveFormKeys = new[] { "creditcard", "ccv", "cvv", "cardnumber", "cardcode", "password", "account", "routing" }; var sensitiveFormData = ctx.Request.Form.AllKeys.Where( k => sensitiveFormKeys.Contains(k.ToLower(), StringComparer.OrdinalIgnoreCase)).ToList(); if (!sensitiveFormData.Any() || Util.IsDebug()) return; var error = new Error(e.Exception, ctx); sensitiveFormData.ForEach(k => error.Form.Set(k, "*****")); ErrorLog.GetDefault(ctx).Log(error); e.Dismiss(); }
protected void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs args) { ElmahFilter.FilterSensitiveData(args); }
// ELMAH Filtering protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e) { FilterError404(e); }
public void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e) { // perform filtering here }
/// <summary> /// Logs an exception and its context to the error log. /// </summary> protected virtual void LogException(Exception e, HttpContextBase context) { if (e == null) throw new ArgumentNullException("e"); // // Fire an event to check if listeners want to filter out // logging of the uncaught exception. // var args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) return; // // Tweet away... // HttpWebRequest request = null; try { var status = StringFormatter.Format(_statusFormat, new Error(e, context)); // // Apply ellipsis if status is too long. If the trimmed // status plus ellipsis yields nothing then just use // the trimmed status without ellipsis. This can happen if // someone gives an ellipsis that is ridiculously long. // var maxLength = _maxStatusLength; if (status.Length > maxLength) { var ellipsis = _ellipsis; var trimmedStatusLength = maxLength - ellipsis.Length; status = trimmedStatusLength >= 0 ? status.Substring(0, trimmedStatusLength) + ellipsis : status.Substring(0, maxLength); } // // Submit the status by posting form data as typically down // by browsers for forms found in HTML. // request = (HttpWebRequest) WebRequest.Create(_url); request.Method = "POST"; // WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; if (_credentials != null) // Need Basic authentication? { request.Credentials = _credentials; request.PreAuthenticate = true; } // See http://blogs.msdn.com/shitals/archive/2008/12/27/9254245.aspx request.ServicePoint.Expect100Continue = false; // // URL-encode status into the form and get the bytes to // determine and set the content length. // var encodedForm = string.Format(_formFormat, Uri.EscapeDataString(status)); var data = Encoding.ASCII.GetBytes(encodedForm); Debug.Assert(data.Length > 0); request.ContentLength = data.Length; // // Get the request stream into which the form data is to // be written. This is done asynchronously to free up this // thread. // // NOTE: We maintain a (possibly paranoid) list of // outstanding requests and add the request to it so that // it does not get treated as garbage by GC. In effect, // we are creating an explicit root. It is also possible // for this module to get disposed before a request // completes. During the callback, no other member should // be touched except the requests list! // _requests.Add(request); var ar = request.BeginGetRequestStream(OnGetRequestStreamCompleted, AsyncArgs(request, data)); } catch (Exception localException) { // // IMPORTANT! We swallow any exception raised during the // logging and send them out to the trace . The idea // here is that logging of exceptions by itself should not // be critical to the overall operation of the application. // The bad thing is that we catch ANY kind of exception, // even system ones and potentially let them slip by. // OnWebPostError(request, localException); } }
/// <summary> /// Logs an exception and its context to the error log. /// </summary> protected virtual void LogException(Exception e, HttpContextBase context) { if (e == null) throw new ArgumentNullException("e"); // // Fire an event to check if listeners want to filter out // logging of the uncaught exception. // ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) return; // // Log away... // ErrorLogEntry entry = null; try { Error error = new Error(e, context); ErrorLog log = GetErrorLog(context); error.ApplicationName = log.ApplicationName; OnLogging(new ErrorLoggingEventArgs(error)); string id = log.Log(error); entry = new ErrorLogEntry(log, id, error); } catch (Exception localException) { // // IMPORTANT! We swallow any exception raised during the // logging and send them out to the trace . The idea // here is that logging of exceptions by itself should not // be critical to the overall operation of the application. // The bad thing is that we catch ANY kind of exception, // even system ones and potentially let them slip by. // Trace.WriteLine(localException); } if (entry != null) OnLogged(new ErrorLoggedEventArgs(entry)); }
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e) { if (e.Exception.GetBaseException() is HttpRequestValidationException) e.Dismiss(); }
/// <summary> /// Reports the exception. /// </summary> protected virtual void OnError(Exception e, HttpContext context, string applciationName) { if (e == null) throw new ArgumentNullException("e"); // // Fire an event to check if listeners want to filter out // reporting of the uncaught exception. // ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) return; // // Get the last error and then report it synchronously or // asynchronously based on the configuration. // Error error = new Error(e, context); if (!string.IsNullOrEmpty(applciationName)) error.ApplicationName = applciationName; if (_reportAsynchronously) ReportErrorAsync(error); else ReportError(error); }
/// <summary> /// Logs an exception and its context to the error log. /// </summary> protected virtual void LogException(Exception e, HttpContextBase context) { if (e == null) { throw new ArgumentNullException("e"); } // // Fire an event to check if listeners want to filter out // logging of the uncaught exception. // ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) { return; } // // Tweet away... // HttpWebRequest request = null; try { string status = StringFormatter.Format(_statusFormat, new Error(e, context)); // // Apply ellipsis if status is too long. If the trimmed // status plus ellipsis yields nothing then just use // the trimmed status without ellipsis. This can happen if // someone gives an ellipsis that is ridiculously long. // int maxLength = _maxStatusLength; if (status.Length > maxLength) { string ellipsis = _ellipsis; int trimmedStatusLength = maxLength - ellipsis.Length; status = trimmedStatusLength >= 0 ? status.Substring(0, trimmedStatusLength) + ellipsis : status.Substring(0, maxLength); } // // Submit the status by posting form data as typically down // by browsers for forms found in HTML. // request = (HttpWebRequest)WebRequest.Create(_url); request.Method = "POST"; // WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; if (_credentials != null) // Need Basic authentication? { request.Credentials = _credentials; request.PreAuthenticate = true; } // See http://blogs.msdn.com/shitals/archive/2008/12/27/9254245.aspx request.ServicePoint.Expect100Continue = false; // // URL-encode status into the form and get the bytes to // determine and set the content length. // string encodedForm = string.Format(_formFormat, HttpUtility.UrlEncode(status)); byte[] data = Encoding.ASCII.GetBytes(encodedForm); Debug.Assert(data.Length > 0); request.ContentLength = data.Length; // // Get the request stream into which the form data is to // be written. This is done asynchronously to free up this // thread. // // NOTE: We maintain a (possibly paranoid) list of // outstanding requests and add the request to it so that // it does not get treated as garbage by GC. In effect, // we are creating an explicit root. It is also possible // for this module to get disposed before a request // completes. During the callback, no other member should // be touched except the requests list! // _requests.Add(request); IAsyncResult ar = request.BeginGetRequestStream( new AsyncCallback(OnGetRequestStreamCompleted), AsyncArgs(request, data)); } catch (Exception localException) { // // IMPORTANT! We swallow any exception raised during the // logging and send them out to the trace . The idea // here is that logging of exceptions by itself should not // be critical to the overall operation of the application. // The bad thing is that we catch ANY kind of exception, // even system ones and potentially let them slip by. // OnWebPostError(request, localException); } }
/// <summary> /// Raises the <see cref="Filtering"/> event. /// </summary> protected virtual void OnFiltering(ExceptionFilterEventArgs args) { ExceptionFilterEventHandler handler = Filtering; if (handler != null) handler(this, args); }
void MyErrorMailModule_Filtering(object sender, ExceptionFilterEventArgs args) { var httpException = args.Exception.GetBaseException() as HttpException; if (httpException != null && httpException.GetHttpCode() == 404) args.Dismiss(); }