Beispiel #1
0
        protected void Application_Error(object sender, EventArgs e)
        {
            bool sendExceptions = false;

            bool.TryParse(ConfigurationManager.AppSettings["SendExceptions"], out sendExceptions);

            var error = Server.GetLastError();
            var code  = (error is HttpException) ? (error as HttpException).GetHttpCode() : 500;

            if (
                sendExceptions &&
                code != 404 &&                                                                                                                  // not existing action is called
                !(error is InvalidOperationException) && !error.Message.StartsWith("Multiple types were found that match the controller named") // same controller name in multpily controller, and no correct action call
                )
            {
                HttpUnhandledException httpUnhandledException =
                    new HttpUnhandledException(error.Message, error);

                ErrorHelper.SendEmailWithErrors(
                    httpUnhandledException.GetHtmlErrorMessage()
                    );

                ErrorHelper.Log(Server.GetLastError().Message);
            }
        }
Beispiel #2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            HttpUnhandledException httpUnhandledException =
                new HttpUnhandledException(Server.GetLastError().Message, Server.GetLastError());

            SendEmailWithErrors(httpUnhandledException.GetHtmlErrorMessage());
        }
        public override void Log(ExceptionLoggerContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            HttpContext httpContext = GetHttpContext(context.Request);

            if (httpContext == null)
            {
                return;
            }

            // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
            string errorMessage = context.Exception.Message;

            try
            {
                using (var stream = context.Request.Content.ReadAsStreamAsync().Result)
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(stream))
                    {
                        string data = reader.ReadToEnd();
                        errorMessage = data + "\n" + errorMessage;
                    }
                }
            }
            catch { }
            Exception exceptionToRaise = new HttpUnhandledException(errorMessage, context.Exception);

            // Send the exception to ELMAH (for logging, mailing, filtering, etc.).
            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
Beispiel #4
0
        protected void Application_Error(object sender, EventArgs e)
        {
#if !DEBUG
            try
            {
                string message = Server.GetLastError().Message;

                //Ignorar OperationCanceledException e HttpException
                if (!message.Contains("This is an invalid webresource request.") && !message.Contains("The operation was canceled."))
                {
                    string infoAdicional = JsonConvert.SerializeObject(Context.Request,
                                                                       Formatting.Indented, new JsonSerializerSettings
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                        ContractResolver      = new IgnoreErrorPropertiesResolver()
                    });

                    var exBase = Server.GetLastError().GetBaseException();
                    HttpUnhandledException httpUnhandledException = new HttpUnhandledException(
                        exBase.Message + Environment.NewLine + "<code>" + infoAdicional + "</code>",
                        exBase.GetBaseException());

                    Task.Run(async() =>
                    {
                        await Utils.SendMailAsync(new MailAddress("*****@*****.**"), "OPS :: " + exBase.Message,
                                                  httpUnhandledException.GetHtmlErrorMessage());
                    }).Wait();
                }
            }
            catch
            {
                // ignored
            }
#endif
        }
        public void StripHttpUnhandledExceptionByDefault()
        {
            HttpUnhandledException wrapper = new HttpUnhandledException("Something went wrong", _exception);

            RaygunMessage message = _client.ExposeBuildMessage(wrapper);

            Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
Beispiel #6
0
        public void DontStripIfNoInnerException()
        {
            HttpUnhandledException wrapper = new HttpUnhandledException();

            List <Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();

            Assert.AreEqual(1, exceptions.Count);
            Assert.Contains(wrapper, exceptions);
        }
Beispiel #7
0
        protected void Application_Error(object sender, EventArgs e)
        {
            HttpUnhandledException httpUnhandledException = new HttpUnhandledException(Server.GetLastError().Message, Server.GetLastError());

            List <string> errorSendTo = new List <string>();

            errorSendTo.Add("*****@*****.**");
            TLC.Data.Email.Send(errorSendTo, "Application Exception Raised", httpUnhandledException.GetHtmlErrorMessage());
        }
Beispiel #8
0
        public void StripHttpUnhandledExceptionByDefault()
        {
            HttpUnhandledException wrapper = new HttpUnhandledException("Something went wrong", _exception);

            List <Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();

            Assert.AreEqual(1, exceptions.Count);
            Assert.Contains(_exception, exceptions);
        }
        public void DontStripIfNoInnerException()
        {
            HttpUnhandledException wrapper = new HttpUnhandledException();

            RaygunMessage message = _client.ExposeBuildMessage(wrapper);

            Assert.AreEqual("System.Web.HttpUnhandledException", message.Details.Error.ClassName);
            Assert.IsNull(message.Details.Error.InnerError);
        }
        public void StripMultipleWrapperExceptions()
        {
            HttpUnhandledException    wrapper  = new HttpUnhandledException("Something went wrong", _exception);
            TargetInvocationException wrapper2 = new TargetInvocationException(wrapper);

            RaygunMessage message = _client.ExposeBuildMessage(wrapper2);

            Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
Beispiel #11
0
        public void StripMultipleWrapperExceptions()
        {
            HttpUnhandledException    wrapper  = new HttpUnhandledException("Something went wrong", _exception);
            TargetInvocationException wrapper2 = new TargetInvocationException(wrapper);

            List <Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper2).ToList();

            Assert.AreEqual(1, exceptions.Count);
            Assert.Contains(_exception, exceptions);
        }
Beispiel #12
0
        public void TestWriteXmlException()
        {
            var ex = new HttpUnhandledException("This is a test");

            var buffer = new StringBuilder();

            using (XmlWriter writer = XmlWriter.Create(buffer))
                ObjectDumper.WriteXml(ex, 1, new[] { "Message" }, writer);

            Assert.AreEqual(296, buffer.ToString().Length);
        }
Beispiel #13
0
        public override void Log(ExceptionLoggerContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            //HttpContext httpContext = GetHttpContext(context.Request);

            // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
            Exception exceptionToRaise = new HttpUnhandledException(message: null, innerException: context.Exception);

            // Send the exception to logger (for logging, mailing, filtering, etc.).
            logger.HandleException(exceptionToRaise, "Dongbo.AxeSlide.Api");
        }
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();

            // The HttpUnhandledException must be unpacked before it can be used.
            HttpUnhandledException unhandledEx = ex as HttpUnhandledException;

            if (unhandledEx != null && unhandledEx.InnerException is InvalidOperationException)
            {
                Server.Transfer("/CustomError.aspx");
            }
        }
        public void OnException(ExceptionContext context)
        {
            // Log only handled exceptions, because all other will be caught by ELMAH anyway.
            if (context.ExceptionHandled)
            {
                // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
                Exception exceptionToRaise = new HttpUnhandledException(message: null, innerException: context.Exception);

                // Send the exception to ELMAH (for logging, mailing, filtering, etc.).
                ErrorSignal.FromCurrentContext().Raise(exceptionToRaise);
            }
        }
Beispiel #16
0
        public override void Log(ExceptionLoggerContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            HttpContext httpContext = GetHttpContext(context.Request);

            //if (httpContext == null) {  return; }

            // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
            Exception exceptionToRaise = new HttpUnhandledException(message: null, innerException: context.Exception);

            // Send the exception to ELMAH (for logging, mailing, filtering, etc.).
            ErrorHelper.LogErrorManually(exceptionToRaise, httpContext);
        }
        public override void OnException(HttpActionExecutedContext context)
        {
            if (context.Exception is BusinessException || context.Exception is OperationCanceledException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = new StringContent(context.Exception.Message),
                    ReasonPhrase = "Exception"
                });
            }

#if DEBUG
            //Log Critical errors
            Debug.WriteLine(context.Exception);

            string sMessage = context.Exception.GetBaseException().Message;
#else
            string infoAdicional = JsonConvert.SerializeObject(context.Request,
                                                               Formatting.Indented, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                ContractResolver      = new IgnoreErrorPropertiesResolver()
            });

            var exBase = context.Exception.GetBaseException();
            HttpUnhandledException httpUnhandledException = new HttpUnhandledException(
                exBase.Message + Environment.NewLine + "<code>" + infoAdicional + "</code>",
                exBase.GetBaseException());

            Task.Run(async() =>
            {
                await Utils.SendMailAsync(new MailAddress("*****@*****.**"), "OPS :: " + exBase.Message,
                                          httpUnhandledException.GetHtmlErrorMessage());
            }).Wait();

            string sMessage = "Ocorreu um erro, tente novamente ou entre em contato com o administrador.";
#endif

            var ex = context.Exception;
            context.Response = context.Request.CreateResponse(HttpStatusCode.InternalServerError,
                                                              new
            {
                ExceptionMessage = sMessage,
                RealStatusCode   = (int)(ex is NotImplementedException || ex is ArgumentNullException ? HttpStatusCode.NoContent : HttpStatusCode.BadRequest)
            },
                                                              new JsonMediaTypeFormatter());

            base.OnException(context);
        }
Beispiel #18
0
        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs
            HttpUnhandledException httpUnhandledException = new HttpUnhandledException(Server.GetLastError().Message, Server.GetLastError());

            string errorInfo         = httpUnhandledException.GetHtmlErrorMessage();
            string detailedErrorInfo = string.Format("An error has been encountered in Mutual Funds Statement Request, Details are mentioned below:\nUser Name: {0}\nEmail: {1}\nPhone: {2}\nPAN: {3}\n\nError Information:\n{3}", AppConfig.FullName, AppConfig.Email, AppConfig.Phone, AppConfig.PAN, errorInfo);

            logger.Error(detailedErrorInfo);
            Console.WriteLine(detailedErrorInfo);

            var emailObj = new Email("Mutual Fund Statement Request - Error Occured", Email.DeveloperEmail, Email.DeveloperName, isHTMLBody: false);

            emailObj.SendEmail(detailedErrorInfo);
        }
Beispiel #19
0
        public override void Log(ExceptionLoggerContext context)
        {
            HttpContext httpContext = GetHttpContext(context.Request);

            if (httpContext == null)
            {
                return;
            }

            Exception exceptionToRaise = new HttpUnhandledException(message: null, innerException: context.Exception);

            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
        public override void Log(ExceptionLoggerContext context)
        {
            var httpContext = GetHttpContext(context.Request);

            if (httpContext == null)
            {
                return;
            }

            Exception exceptionToRaise = new HttpUnhandledException(null, context.Exception);

            var signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
Beispiel #21
0
        public override void Log(ExceptionLoggerContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            HttpContext httpContext = GetHttpContext(context.Request);

            if (httpContext == null)
            {
                return;
            }
            var exceptionToRaise = new HttpUnhandledException(message: null, innerException: context.Exception);
            var logger           = LogManager.GetLogger(this.GetType());
            var msg = CreateErrorMessage(exceptionToRaise);

            logger.Error(msg, exceptionToRaise);
        }
        public void LogUnhandledException_EventArgsWithHttpUnhandledException_DoesLog()
        {
            // Arrange
            var    moduleUnderTest = new TestAspNetExceptionLoggingModule();
            object exceptionToLog  = new HttpUnhandledException();
            var    eventArgs       = new UnhandledExceptionEventArgs(exceptionToLog, false);

            using (var scope = new LoggingProviderScope(ScopeOption.AllowOnlyASingleEntryToBeLogged))
            {
                // Act
                moduleUnderTest.LogUnhandledException(null, eventArgs);

                // Assert
                Assert.AreEqual(1, scope.LoggedEntries.Count());
            }
        }
        void context_Error(object sender, EventArgs e)
        {
            Exception source = this.httpApplication.Server.GetLastError();

            if (ValidateRequest(this.httpApplication.Context.Request))
            {
                var ex = new HttpUnhandledException(source.Message, source);
                ex.HandleException();
            }
            else
            {
                var msg = string.Format("[HostileRequest]{0}", source.Message);
                var ex  = new HostileRequestException(msg, source);
                ex.HandleException();
            }
        }
Beispiel #24
0
        private void Log(ExceptionContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            HttpContext httpContext = context.HttpContext.ApplicationInstance.Context;

            if (httpContext == null)
            {
                return;
            }

            // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
            Exception exceptionToRaise = new HttpUnhandledException(message: null, innerException: context.Exception);

            // Send the exception to ELMAH (for logging, mailing, filtering, etc.).
            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
        public override void Log(ExceptionLoggerContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            HttpContext httpContext = GetHttpContext(context.Request);

            if (httpContext == null)
            {
                return;
            }

            // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
            Exception exceptionToRaise = new HttpUnhandledException(context.Exception.Message, context.Exception);

            // Send the exception to ELMAH (for logging, mailing, filtering, etc.).
            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
        public void Error_WithHttpUnhandledExceptionWithoutInnerException_LogsHttpUnhandledException()
        {
            // Arrange
            var moduleUnderTest   = new TestAspNetExceptionLoggingModule();
            var context           = new HttpApplication();
            var expectedException = new HttpUnhandledException("some message");

            moduleUnderTest.Init(context);

            using (var scope = new LoggingProviderScope(ScopeOption.AllowOnlyASingleEntryToBeLogged))
            {
                // Act
                RaisErrorOnContext(context, expectedException);
                var actualException = scope.LoggedEntries.First().Exception;

                // Assert
                Assert.AreEqual(expectedException, actualException);
            }
        }
Beispiel #27
0
        public void OnException(ExceptionContext filterContext)
        {
            var exSource = filterContext.Exception;

            if (null == exSource)
            {
                return;
            }

            var ex = new HttpUnhandledException(exSource.Message, exSource);

            HandleException(ex, null);
            filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            filterContext.Result = new ContentResult()
            {
                Content = new MessageResult()
                {
                    Message = ex.Message
                }.ToJson()
            };
        }
Beispiel #28
0
        protected void Application_Error(object sender, EventArgs e)
        {
            Application["LastError"] = Server.GetLastError();

#if DEBUG
            var    lastError = Server.GetLastError();
            string sql       = null;

            try
            {
                sql = lastError.Data["SQL"] as string;
            }
            catch
            {
                // skip it
            }

            if (sql == null)
            {
                return;
            }

            var ex = new HttpUnhandledException("An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.", lastError);

            Server.ClearError();

            var html      = ex.GetHtmlErrorMessage();
            var traceNode = "<b>Stack Trace:</b>";
            html = html.Replace(traceNode, @"<b>Sql:</b><br><br>
    <table width='100%' bgcolor='#ffffccc'>
    <tbody><tr><td><code><pre>" + sql + @"</pre></code></td></tr></tbody>
    </table><br>" + traceNode);

            HttpContext.Current.Response.Write(html);
            HttpContext.Current.Response.StatusCode = 500;
            HttpContext.Current.Response.Status     = "Internal Server Error";
            HttpContext.Current.Response.End();
#endif
        }
Beispiel #29
0
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            var exSource = actionExecutedContext.Exception;

            if (null == exSource)
            {
                return;
            }

            var ex = new HttpUnhandledException(exSource.Message, exSource);

            HandleException(ex, null);

            if (actionExecutedContext.Response == null)
            {
                actionExecutedContext.Response = new HttpResponseMessage();
            }
            actionExecutedContext.Response.StatusCode = HttpStatusCode.InternalServerError;
            actionExecutedContext.Response.Content    = new StringContent(new MessageResult()
            {
                Message = ex.Message
            }.ToJson());
        }
        public void ImportarDados(string value)
        {
            if (DateTime.Now.Hour != 3 || value != System.Web.Configuration.WebConfigurationManager.AppSettings.Get("TaskKey"))
            {
                return;
            }

            Task.Run(async() =>
            {
                var tempPath = System.Web.Hosting.HostingEnvironment.MapPath("~/temp/");

                try
                {
                    var sb       = new StringBuilder();
                    Stopwatch sw = Stopwatch.StartNew();
                    TimeSpan t;

                    Camara.ImportaPresencasDeputados();
                    t = TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds);
                    sb.AppendFormat("<p>ImportaPresencasDeputados: {0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms</p>", t.Hours, t.Minutes, t.Seconds, t.Milliseconds);
                    sw.Restart();


                    sw.Stop();

                    await Utils.SendMailAsync(new MailAddress("*****@*****.**"), "OPS :: Resumo da Importação", sb.ToString());
                }
                catch (Exception ex)
                {
                    HttpUnhandledException httpUnhandledException = new HttpUnhandledException(
                        ex.GetBaseException().Message, ex.GetBaseException());

                    await Utils.SendMailAsync(new MailAddress("*****@*****.**"), "OPS :: Informe de erro na Importação",
                                              httpUnhandledException.GetHtmlErrorMessage());
                }
            });
        }
        Exception BuildParseError(Exception e, string capsKey) {
            string message = SR.GetString(SR.Invalid_string_from_browser_caps, e.Message, capsKey, this[capsKey]);

            // to show ConfigurationException in stack trace
            ConfigurationErrorsException configEx = new ConfigurationErrorsException(message, e);

            // I want it to look like an unhandled exception
            HttpUnhandledException httpUnhandledEx = new HttpUnhandledException(null, null);

            // but show message from outer exception (it normally shows the inner-most)
            httpUnhandledEx.SetFormatter(new UseLastUnhandledErrorFormatter(configEx));

            return httpUnhandledEx;
        }