Example #1
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
        }
Example #2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            HttpUnhandledException httpUnhandledException =
                new HttpUnhandledException(Server.GetLastError().Message, Server.GetLastError());

            SendEmailWithErrors(httpUnhandledException.GetHtmlErrorMessage());
        }
Example #3
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);
            }
        }
Example #4
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());
        }
        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);
        }
Example #6
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);
        }
Example #7
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
        }
        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());
                }
            });
        }
Example #9
0
        //DID not work the OR and IN search implementation
        //protected void Application_Start(object sender, EventArgs e)
        //{

        //    Lucene.Net.Analysis.StopAnalyzer.ENGLISH_STOP_WORDS_SET = new System.Collections.Hashtable();


        //}

        protected void Application_Error(object sender, EventArgs e)
        {
            // Get the error details
            var lastErrorWrapper = Server.GetLastError();

            Exception lastError = lastErrorWrapper;

            if (lastErrorWrapper.InnerException != null)
            {
                lastError = lastErrorWrapper.InnerException;
            }

            string lastErrorTypeName   = lastError.GetType().ToString();
            string lastErrorMessage    = lastError.Message;
            string lastErrorStackTrace = lastError.StackTrace;


            const string Subject = "An Error Has Occurred!";

            string htmlyellomsg = string.Empty;


            HttpUnhandledException httpUnhandledException = new HttpUnhandledException(Server.GetLastError().Message, Server.GetLastError());

            htmlyellomsg = httpUnhandledException.GetHtmlErrorMessage();

            //If you do not call Server.ClearError or trap the error in the Page_Error or Application_Error event handler,
            //the error is handled based on the settings in the section of the Web.config file.

            //////Server.ClearError();

            //Prepare Mail Object
            ShiptalkMailMessage mm = new ShiptalkMailMessage(true, ShiptalkMailMessage.MailFrom.ShiptalkResourceCenter);


            mm.ToList.Add(ConfigUtil.CriticalErrorEmail);

            if (ConfigUtil.CriticalErrorEmailCC.Length > 0)
            {
                mm.ToList.Add(ConfigUtil.CriticalErrorEmailCC);
            }

            mm.Subject = Subject;

            mm.Body = string.Format(@"
                                    <html>
                                    <body>
                                      <h1>An Error Has Occurred!</h1>
                                      <table cellpadding=""5"" cellspacing=""0"" border=""1"">
                                      <tr>
                                      <tdtext-align: right;font-weight: bold"">URL:</td>
                                      <td>{0}</td>
                                      </tr>
                                      <tr>
                                      <tdtext-align: right;font-weight: bold"">User:</td>
                                      <td>{1}</td>
                                      </tr>
                                      <tr>
                                      <tdtext-align: right;font-weight: bold"">Exception Type:</td>
                                      <td>{2}</td>
                                      </tr>
                                      <tr>
                                      <tdtext-align: right;font-weight: bold"">Message:</td>
                                      <td>{3}</td>
                                      </tr>
                                      <tr>
                                      <tdtext-align: right;font-weight: bold"">Stack Trace:</td>
                                      <td>{4}</td>
                                      </tr> 

                                      </table>
                                    </body>
                                    </html>
                                        {5}
                                        ",
                                    Request.RawUrl,
                                    User.Identity.Name,
                                    lastErrorTypeName,
                                    lastErrorMessage,
                                    lastErrorStackTrace.Replace(Environment.NewLine, "<br />"),
                                    htmlyellomsg
                                    )
            ;


            //// Attach the Yellow Screen of Death for this error
            //string YSODmarkup = lastErrorWrapper.GetHtmlErrorMessage();
            //if (!string.IsNullOrEmpty(YSODmarkup))
            //{

            //}


            //Send Mail here
            if (ConfigUtil.WebEnvironment != "dev")
            {
                ShiptalkMail mail = new ShiptalkMail(mm);
                mail.SendMail();
            }
        }