Example #1
0
        protected override void OnError(Exception e, HttpContext context)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context);

            OnFiltering(args);

            if (args.Dismissed)
            {
                return;
            }

            Error error = GetError(e, context);

            if (IsAsync)
            {
                ReportErrorAsync(error);
            }
            else
            {
                ReportError(error);
            }
        }
Example #2
0
        protected override void OnError(Exception e, HttpContext context)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, (object)context);

            this.OnFiltering(args);
            if (args.Dismissed)
            {
                return;
            }
            //FIX STARTS
            //Error error = new Error(e, context);
            Error error = ElmahErrorLogModuleFix.CreateErrorSafe(e, context);

            //FIX ENDS
            if (this._reportAsynchronously2)
            {
                this.ReportErrorAsync(error);
            }
            else
            {
                this.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;
                    }
                }
            }
        }
Example #4
0
        protected override void OnError(Exception e, HttpContext context)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            ExceptionFilterEventArgs exceptionFilterEventArgs = new ExceptionFilterEventArgs(e, context);

            OnFiltering(exceptionFilterEventArgs);
            if (!exceptionFilterEventArgs.Dismissed)
            {
                Error error = new Error(e, context);
                if (!string.IsNullOrEmpty(error.Message))
                {
                    string ErrorMessage = error.Message;
                    if (ErrorMessage.Contains("Connection Data Source"))
                    {
                        int    firstIndex  = ErrorMessage.IndexOf("Connection Data Source");
                        string firstPart   = ErrorMessage.Substring(0, firstIndex);
                        string temp        = ErrorMessage.Substring(firstIndex);
                        int    secondIndex = temp.IndexOf("at Sql");
                        string secondPart  = secondIndex > 0 ? temp.Substring(secondIndex) : "";
                        error.Message = firstPart + secondPart;
                    }
                }
                ReportError(error);
            }
        }
        private void OnError(Exception e, HttpContext context)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            var args = new ExceptionFilterEventArgs(e, context);

            OnFiltering(args);
            if (args.Dismissed)
            {
                return;
            }

            var error = new Error(e, context);

            if (_config.ReportAsynchronously)
            {
                ReportErrorAsync(error);
            }
            else
            {
                ReportError(error);
            }
        }
Example #6
0
        void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            //TODO read in xml log files
            //Elmah.XmlFileErrorLog log = new XmlFileErrorLog("~/ElmahLog");

            ElmahError err = new ElmahError();


            //using (var context = new ElmahContext())
            //{
            //    //if the exception had the same message and was from
            //    //the last 10 min it means it's the same we dismiss it
            //    _sendEmail = true;
            //    var lastErr = context.ELMAH_Errors
            //    .OrderByDescending(m => m.TimeUtc).Take(1)
            //    .SingleOrDefault();
            //    if (lastErr != null &&
            //    (e.Exception.Message == lastErr.Message &&
            //    lastErr.TimeUtc > DateTime.UtcNow.AddMinutes(-10)))
            //    {
            //        e.Dismiss();
            //        _sendEmail = false;
            //    }
            //}

            if (e.Exception.GetBaseException() is HttpRequestValidationException)
            {
                e.Dismiss();
            }
        }
Example #7
0
 void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
 {
     if (e.Exception.Message.StartsWith(@"File does not exist"))
     {
         e.Dismiss();
     }
 }
        //protected  void Application_BeginRequest()
        //{
        //    System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
        //}

        protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            if (SecurityUtils.ErrorMsgstoIgnore(e.Exception.Message))
            {
                e.Dismiss();
            }
        }
Example #9
0
        public void ErrorLog_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();
            }
            else if (IsEmailBodyError(ex))
            {
                e.Dismiss();
            }
            FilterOutSensitiveFormData(e);
        }
Example #10
0
 void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
 {
     if (e.Exception.GetBaseException() is HttpRequestValidationException)
     {
         e.Dismiss();
     }
 }
Example #11
0
        private void Filter(ExceptionFilterEventArgs e)
        {
            var ex     = e.Exception.GetBaseException();
            var httpex = ex as HttpException;

            if (httpex != null)
            {
                if (httpex.GetHttpCode() == 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();
            }
        }
 private void OnFiltering(ExceptionFilterEventArgs args)
 {
     var handler = Filtering;
     if (handler == null)
         return;
     handler(this, args);
 }
Example #13
0
        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);
        }
Example #14
0
        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();
        }
 private void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
 {
     if (e.Exception is System.Threading.ThreadAbortException)
     {
         e.Dismiss();
     }
 }
Example #16
0
 public void OnErrorModuleFiltering(object sender, ExceptionFilterEventArgs args)
 {
     // We skip our custom exceptions
     if (args.Exception is DomainException)
     {
         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 ErrorLogEntry LogException(Exception e, HttpContext 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(null);
            }

            //
            // Log away...
            //

            ErrorLogEntry entry = null;

            try
            {
                Error    error = new Error(e, context);
                ErrorLog log   = GetErrorLog(context);
                error.ApplicationName = log.ApplicationName;
                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));
            }

            return(entry);
        }
        private void OnFiltering(ExceptionFilterEventArgs args)
        {
            var handler = Filtering;

            if (handler == null)
            {
                return;
            }
            handler(this, args);
        }
 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();
         }
     }
 }
Example #21
0
 private static void FilterError404(ExceptionFilterEventArgs e)
 {
     if (e.Exception.GetBaseException() is HttpException)
     {
         var exception = (HttpException)e.Exception.GetBaseException();
         if (exception.GetHttpCode() == 404)
         {
             e.Dismiss();
         }
     }
 }
Example #22
0
        public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            Check.Argument.IsNotNull(e, "e");

            var exception = e.Exception.GetBaseException() as HttpException;

            if ((exception != null) && (exception.GetHttpCode() == (int)HttpStatusCode.NotFound))
            {
                e.Dismiss();
            }
        }
Example #23
0
        void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            bool sendMail = false;

            var context = e.Context as HttpContext;

            var error = new Error(e.Exception, context);

            try
            {
                string ErrorMailKey = Convert.ToString(ConfigurationManager.AppSettings["ErrorMailKey"]);
                if (ErrorMailKey != null)
                {
                    if (ErrorMailKey.Contains(","))
                    {
                        string[] getErrorTypes = ErrorMailKey.Split(',');

                        foreach (string err in getErrorTypes)
                        {
                            int    StatusCode = Convert.ToInt32(err.Split(':')[0]);
                            string errType    = err.Split(':')[1].ToString();

                            if (error.StatusCode == StatusCode && error.Type == errType)
                            {
                                sendMail = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        int    StatusCode = Convert.ToInt32(ErrorMailKey.Split(':')[0]);
                        string errType    = ErrorMailKey.Split(':')[1].ToString();
                        if (error.StatusCode == StatusCode && error.Type == errType)
                        {
                            sendMail = true;
                        }
                    }

                    if (!sendMail)
                    {
                        e.Dismiss();
                    }
                }
                else
                {
                    e.Dismiss();
                }
            }
            catch (Exception)
            {
                e.Dismiss();
            }
        }
        private static object EvaluateToException(object context)
        {
            //
            // Assume the reasonable default that the user wants the
            // exception from the context. If the context is not the
            // expected type so resort to late-binding.
            //

            ExceptionFilterEventArgs args = context as ExceptionFilterEventArgs;

            return(args != null ? args.Exception : DataBinder.Eval(context, "Exception"));
        }
Example #25
0
 /// <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);
         }
     }
 }
Example #26
0
        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
        }
Example #27
0
 public void OnErrorModuleFiltering(object sender, ExceptionFilterEventArgs args)
 {
     if (args.Exception.GetBaseException() is FileNotFoundException)
     {
         args.Dismiss();
     }
     if (args.Context is HttpContext httpContext)
     {
         if (httpContext.Response.StatusCode == 404)
         {
             args.Dismiss();
         }
     }
 }
Example #28
0
        protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
        {
            if (!(e.Exception.GetBaseException() is HttpException))
            {
                return;
            }

            var ex = (HttpException)e.Exception.GetBaseException();

            if (ex.GetHttpCode() == 404)
            {
                e.Dismiss(); // ignora o erro
            }
        }
Example #29
0
        void Filter(ExceptionFilterEventArgs args)
        {
            if (args.Exception.GetBaseException() is MorpherException && !(args.Exception.GetBaseException() is ServerException))
            {
                args.Dismiss();
            }

            var statusCode = HttpContext.Current.Response.StatusCode;

            if (statusCode != (int)HttpStatusCode.InternalServerError)
            {
                args.Dismiss();
            }
        }
        void Filter(ExceptionFilterEventArgs args)
        {
            if (args.Exception.GetBaseException() is MorpherException && !(args.Exception.GetBaseException() is ServerException))
            {
                args.Dismiss();
            }

            var statusCode = (args.Exception as HttpException)?.GetHttpCode() ?? -1;

            if (statusCode != (int)HttpStatusCode.InternalServerError)
            {
                args.Dismiss();
            }
        }
Example #31
0
        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();
        }
        private void OnError(Exception e, HttpContext context)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            var args = new ExceptionFilterEventArgs(e, context);
            OnFiltering(args);
            if (args.Dismissed)
                return;

            var error = new Error(e, context);
            if (_config.ReportAsynchronously)
                ReportErrorAsync(error);
            else
                ReportError(error);
        }
 public void LogException(Exception exception, HttpContext httpContext)
 {
     if (exception == null)
     {
         throw new ArgumentNullException("exception");
     }
     if (httpContext == null)
     {
         throw new ArgumentNullException("httpContext");
     }
     var args = new ExceptionFilterEventArgs(exception, httpContext);
     this.OnFiltering(this, args);
     if (args.Dismissed)
     {
         return;
     }
     var error = new Error(exception, httpContext);
     LogInternal(error, httpContext);
 }
 protected void OnFiltering(ExceptionFilterEventArgs args)
 {
     ExceptionFilterEventHandler filtering = this.Filtering;
     if (filtering != null)
     {
         filtering.Invoke(this, args);
     }
 }