protected void Application_Error() { Exception exception = Server.GetLastError(); MailComponent.SendEmailTest("[email protected],[email protected]", "", "", "Error", exception.StackTrace + "Message:: " + exception.ToString(), null, null, true); Response.Clear(); HttpException httpException = exception as HttpException; //if (httpException != null) //{ // string action; // switch (httpException.GetHttpCode()) // { // case 404: // // page not found // action = "HttpError404"; // break; // case 500: // // server error // action = "HttpError500"; // break; // default: // action = "Index"; // break; // } // // clear error on server // Server.ClearError(); // Response.Redirect(String.Format("~/Error/{0}?message={0}", action, HttpUtility.UrlEncode(exception.StackTrace))); //Exception error = Server.GetLastError(); //var code = (error is HttpException) ? (error as HttpException).GetHttpCode() : 500; //if (code == 404) //{ // Response.Redirect("/Account/Login"); //} //Response.Clear(); //Server.ClearError(); //if (ex is ThreadAbortException) // return; //Logger.Error(LoggerType.Global, ex, "Exception"); Response.Redirect("/Account/Login"); //} //else //{ // Server.ClearError(); // Response.Redirect("~/Error"); //} }
public override void OnException(ExceptionContext filterContext) { if (filterContext.ExceptionHandled) { return; } else { Exception ex = filterContext.Exception; filterContext.ExceptionHandled = true; var model = new HandleErrorInfo(new Exception(), "Controller", "Action"); try { var controllerName = filterContext.Controller.ControllerContext.RouteData.Values["controller"].ToString(); var actionName = filterContext.Controller.ControllerContext.RouteData.Values["action"].ToString(); model = new HandleErrorInfo(ex.GetBaseException(), controllerName, actionName); string headerMessage = "<h1>" + ex.Message + "</h1> <br/><br/>"; Task.Run(() => MailComponent.SendEmailTest("[email protected],[email protected]", "", "", "Error", headerMessage + ex.StackTrace + "<br/><br/><br/> Message:: " + ex.GetBaseException(), null, null, true)); } catch (Exception) { } if (filterContext.HttpContext.Request.IsAjaxRequest()) { filterContext.Result = new JsonResult { Data = new { status = false, message = filterContext.Exception.GetBaseException().Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } else { filterContext.Result = new ViewResult() { ViewName = "Error", ViewData = new ViewDataDictionary(model) }; } // throw new Exception(); base.OnException(filterContext); } }
protected void Application_Error() { Exception exception = Server.GetLastError(); HttpException httpException = exception as HttpException; string action = "Index"; if (exception != null) { MailComponent.SendEmailTest("[email protected],[email protected]", "", "", "From Application Error", exception.StackTrace + "<br/><br/> Message:: " + exception.GetBaseException() + DateTime.Now, null, null, true); } if (httpException != null) { switch (httpException.GetHttpCode()) { case (int)HttpStatusCode.NotFound: action = "NotFound"; break; case (int)HttpStatusCode.Forbidden: action = "Forbidden"; break; case (int)HttpStatusCode.InternalServerError: action = "InternalServerError"; break; case (int)HttpStatusCode.Unauthorized: action = "Unauthorized"; break; default: break; } } Response.Clear(); Server.ClearError(); Server.TransferRequest(string.Format("~/Error/{0}", action)); }
public static void SendErrorMail(Exception ex) { MailComponent.SendEmailTest("[email protected],[email protected]", "", "", "Error", ex.StackTrace + "Message:: " + ex.ToString(), null, null, true); }