void Application_Error(object sender, EventArgs e) { HttpException exception = ((HttpApplication)sender).Context.Error as HttpException; LogManager.Error(typeof(HttpApplication), exception ?? ((HttpApplication)sender).Server.GetLastError()); #if !DEBUG int?errorCode = exception?.GetHttpCode() ?? 503; switch (errorCode) { case 401: Response.Redirect("/AccessNoRight"); break; case 404: Response.Redirect("/PageNotFound"); break; case 500: Response.Redirect("/ServerError"); break; case 503: Response.Redirect("/ServiceUnavailable"); break; default: return; } #endif }
protected void Application_Error() { Exception ex = Server.GetLastError(); HttpException httpEx = ex as HttpException; int statusCode = httpEx?.GetHttpCode() ?? 500; Log.Logger.Error(ex, string.Empty); Server.ClearError(); Server.TransferRequest($"/Error/{statusCode}"); }
protected void Application_Error(object sender, EventArgs e) { Exception serverException = this.Server.GetLastError(); HttpException httpException = serverException as HttpException; if (httpException?.GetHttpCode() == 404) { return; } ILog logger = ServiceLocator.Resolve <ILog>(); Guid uniqueId = Guid.NewGuid(); logger.Fatal(uniqueId, serverException); }
protected void Aplication_Error() { Exception ex = Server.GetLastError(); //Borramos el contenido del buffer Response.Clear(); HttpException httpException = ex as HttpException; //404 //Si la variable != null se toma el codigo de la excepcion sino se asigna cero var codError = httpException?.GetHttpCode() ?? 0; //--- --- --- Serr Server.ClearError(); Response.Redirect("~/Inscripcion/Error/" + codError); }
private void DealErroy() { HttpException erroy = new HttpException(); string strCode = erroy.ErrorCode.ToString(); string strMsg = erroy.Message; erroy.HelpLink = "sss"; Response.Write("ErrorCode:" + strCode + "<br />"); Response.Write("Message:" + strMsg + "<br />"); Response.Write("HelpLink:" + erroy.HelpLink + "<br />"); Response.Write("Source:" + erroy.Source + "<br />"); Response.Write("TargetSite:" + erroy.TargetSite + "<br />"); Response.Write("InnerException:" + erroy.InnerException + "<br />"); Response.Write("StackTrace:" + erroy.StackTrace + "<br />"); Response.Write("GetHtmlErrorMessage:" + erroy.GetHtmlErrorMessage() + "<br />"); Response.Write("erroy.GetHttpCode().ToString():" + erroy.GetHttpCode().ToString() + "<br />"); Response.Write("erroy.Data.ToString()::" + erroy.Data.ToString() + "<br />"); }
protected void Page_Load(object sender, EventArgs e) { ex = (HttpException)Server.GetLastError(); int httpCode = ex.GetHttpCode(); // Filter for Error Codes and set text if (httpCode >= 400 && httpCode < 500) { ex = new HttpException (httpCode, "Safe message for 4xx HTTP codes.", ex); } else if (httpCode > 499) { ex = new HttpException (ex.ErrorCode, "Safe message for 5xx HTTP codes.", ex); } else { ex = new HttpException (httpCode, "Safe message for unexpected HTTP codes.", ex); } // Log the exception and notify system operators ExceptionUtility.LogException(ex, "HttpErrorPage"); ExceptionUtility.NotifySystemOps(ex); // Fill the page fields exMessage.Text = ex.Message; exTrace.Text = ex.StackTrace; // Show Inner Exception fields for local access if (ex.InnerException != null) { innerTrace.Text = ex.InnerException.StackTrace; InnerErrorPanel.Visible = Request.IsLocal; innerMessage.Text = string.Format("HTTP {0}: {1}", httpCode, ex.InnerException.Message); } // Show Trace for local access exTrace.Visible = Request.IsLocal; // Clear the error from the server Server.ClearError(); }
public void Application_Error() { ILogger logger = DependencyResolver.Current.GetService <ILogger>(); Exception exception = Server.GetLastError(); logger.Log(exception); if (Request.RequestContext.HttpContext.Request.IsAjaxRequest()) { Response.Clear(); Server.ClearError(); Response.StatusCode = 500; Response.ContentType = "application/json; charset=utf-8"; if (Context.IsCustomErrorEnabled) { Response.Write(JsonConvert.SerializeObject(new { status = "error", data = new { message = Strings.SystemError } })); } else { Response.Write(JsonConvert.SerializeObject(new { status = "error", data = new { message = Strings.SystemError, trace = exception.Message + Environment.NewLine + exception.StackTrace } })); } } else if (Context.IsCustomErrorEnabled) { Server.ClearError(); UrlHelper url = new UrlHelper(Request.RequestContext); RouteValueDictionary route = new RouteValueDictionary(); HttpException httpException = exception as HttpException; route["language"] = Request.RequestContext.RouteData.Values["language"]; route["controller"] = "Home"; route["action"] = "Error"; route["area"] = ""; if (httpException?.GetHttpCode() == 404) { route["action"] = "NotFound"; } Response.TrySkipIisCustomErrors = true; Response.Redirect(url.RouteUrl(route)); } }
protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); if (exception != null) { Response.Clear(); HttpException httpException = exception as HttpException; RouteData routeData = new RouteData(); routeData.Values.Add("controller", "Home"); if (httpException == null) { routeData.Values.Add("action", "Error"); if (exception != null) { Log.Error(exception, "Exception caught in Global.asax1"); } } else { switch (httpException.GetHttpCode()) { case 404: routeData.Values.Add("action", "PageNotFound"); break; case 500: routeData.Values.Add("action", "ServerError"); Log.Error(exception, "500 Exception caught in Global.asax"); break; default: routeData.Values.Add("action", "Error"); Log.Error(exception, "Exception caught in Global.asax (code {Code})", httpException.GetHttpCode()); break; } } Server.ClearError(); Response.TrySkipIisCustomErrors = true; IController errorController = new HomeController(); errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData)); } }
protected void Application_Error(object sender, EventArgs e) { //Hatayý Yakala Exception exception = Server.GetLastError(); Response.Clear(); HttpException httpException = exception as HttpException; if (httpException != null) { //log bilgileri LogInfo log = new LogInfo { Url = Request.Url.ToString(), HataMesaji = httpException.Message, EklenmeTarihi = DateTime.Now, Ip = KullaniciIpAdres.KullaniciIpBul(), Tarayici = Request.Browser.Browser, Dil = Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"].Substring(0, 2) }; switch (httpException.GetHttpCode()) { case 403: Response.Redirect("/Hata/ErisimIzniYok"); break; case 404: Response.Redirect("/Hata/SayfaBulunamadi"); break; case 500: Response.Redirect("/Hata/SunucuHatasý"); break; default: Response.Redirect("/Hata/SayfaBulunamadi"); break; } Server.ClearError(); } }
//EN ESTE METODO SE CAPTURAN LAS PETICIONES DE ERROR //INCONTROLABLES POR FILTER O POR EXCEPTION protected void Application_Error() { //debemos crear la excepcion que esta llamando al metodo actualmente Exception ex = Server.GetLastError(); //estamos en entorno http las excepciones que queremos capturar tienen codigos http //debemos convertir nuestro exception general a un tipo de excepcion http HttpException httpexception = ex as HttpException; //el objeto httpexception contiene los codigos de error http //almacenamos la accion donde deseamos enviar dependiendo de los errores http String accion = ""; switch (httpexception.GetHttpCode()) { case 404: accion = "PaginaNoEncontrada"; break; case 403: //forbidden accion = "ErrorGeneral"; break; default: accion = "ErrorGeneral"; break; } //al capturar las excepciones globales debemos limpiar el contexto del error Context.ClearError(); //redireccionamos pero no lo vamos a hacer con routing //vamos a enviar la peticion request directamente al controlador error //necesitamos ROUTEdata para indicar donde vamos a ir RouteData rutaerror = new RouteData(); //añadimos a la ruta el controlador y el action rutaerror.Values.Add("controller", "Error"); rutaerror.Values.Add("action", accion); //para poder ejecutar la peticion a un controlador //con una ruta, necesitamos la clase icontroller que permite ejecutar otra peticion IController controlador = new ErrorController(); //mediante el metodo execute, redirigimos el request, enviando el contexto(Context) y RouteData controlador.Execute( new RequestContext(new HttpContextWrapper(Context), rutaerror)); }
protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); Response.Clear(); HttpException httpException = exception as HttpException; if (httpException != null) { switch (httpException.GetHttpCode()) { case 404: // page not found Response.Redirect("~/Home/HttpError404/"); break; case 403: // page not found Response.Redirect("~/Home/HttpError403/"); break; case 500: // page not found Response.Redirect("~/Home/HttpError500/"); break; default: Response.Redirect("~/Home/HttpError/"); break; } // clear error on server Server.ClearError(); } else { int index = exception.StackTrace.IndexOf("System"); logger.Error(exception.StackTrace.Remove(index - 3)); logger.Error(exception.Message); Response.Redirect("~/Home/HttpError/"); } }
protected virtual void Application_Error(object sender, EventArgs e) { Exception exception = this.Server.GetLastError().GetBaseException(); HttpException httpException = exception as HttpException; if (httpException == null) { Log.Error(exception.Message, exception); } else { int statusCode = httpException.GetHttpCode(); if (statusCode != (int)HttpStatusCode.NotFound && statusCode != (int)HttpStatusCode.ServiceUnavailable) { Log.Error(exception.Message, httpException); } } }
protected void Application_Error(Object sender, EventArgs e) { Exception exception = Server.GetLastError(); string err_msg = ""; if (exception != null) { HttpException httpException = exception as HttpException; if (httpException != null) { int errorCode = httpException.GetHttpCode(); if (errorCode == 400 || errorCode == 404) { Response.StatusCode = 404; Response.Redirect(string.Format("~/Error/Error404"), true); Server.ClearError(); return; } } var postData = string.Empty; try { using (System.IO.Stream stream = Request.InputStream) { using (System.IO.StreamReader streamReader = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8)) { postData = streamReader.ReadToEnd(); } } } catch { } //該方法為寫錯誤日誌和發送錯誤郵件給開發者的方法(可忽略) //LogCache.Instance.saveToLog(Request, AppDomain.CurrentDomain.BaseDirectory + @"\privateFolder\SysLog\Error\", DateTime.Now.ToString("yyyyMMddHH") + ".log", postData, exception.ToString()); err_msg = exception.Message; CService.msg_write("Error", exception.Message, exception.StackTrace, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodBase.GetCurrentMethod().Name); Response.StatusCode = 500; Response.Redirect(string.Format("~/Error/Error500"), true); Server.ClearError(); } }
protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); Response.Clear(); HttpException httpException = exception as HttpException; int error = httpException != null?httpException.GetHttpCode() : 500; Server.ClearError(); _Logger.Error(String.Format("{0}|{1}", error, exception)); //_Logger.Error(filterContext.Exception); //Response.Redirect(String.Format("~/ErrorHandler/ApplicationError?error={0}&message={1}", error, exception.Message)); Response.Redirect(String.Format("~/ErrorHandler/ApplicationError?error={0}", error, exception.Message)); }
/* * Edit FÜ - 21.10.2012 21:20 Gereksiz taglar temizlendi. Elmah eklendi. */ void Application_Error(object sender, EventArgs e) { try { #region Error Func if (bool.Parse(Class.Fonksiyonlar.Genel.OzelAyar("HataModu"))) { Exception E = Server.GetLastError(); Response.Clear(); HttpException HE = E as HttpException; if (HE != null) { int action = -1; switch (HE.GetHttpCode()) { case 404: action = 404; break; case 500: action = 500; break; default: action = 0; break; } Server.ClearError(); Response.Redirect(String.Format("~/?error={0}-{1}", action, Class.Fonksiyonlar.Genel.StringIslemleri(Class.Sabitler.StringIslemleri.StringIslemTipleri.Etiket, Class.Fonksiyonlar.Genel.StringIslemleri(Class.Sabitler.StringIslemleri.StringIslemTipleri.StringTemizleAdres, (E.Message))))); Context.ApplicationInstance.CompleteRequest(); } } #endregion } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } }
/// <summary> /// Application Error /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); HttpException httpException = exception as HttpException; ErrorLog.WriteLog("GlobalError", "Application_Error", exception, string.Empty); if (AppSettingsUtility.GetBool(AppSettingsKeys.EnableCustomError)) { if (httpException != null && httpException.GetHttpCode() == 404) { Response.Redirect("/page-not-found/"); } else { Response.Redirect("/error/"); } } }
//public static Dictionary<String, String[]> RegistroEmpresasPalena = File.ReadLines(@"C:\FE\wkhtmltopdf\bin\EMPRESAS_PALENA.csv").Select(line => line.Split(';')).ToDictionary( // items => items[0], // items => items // ); protected void Application_Error(object sender, EventArgs e) { bool isLocal = Request.IsLocal; if (isLocal == false) { Exception exception = Server.GetLastError(); Response.Clear(); Response.TrySkipIisCustomErrors = true; HttpException httpException = exception as HttpException; int error = httpException != null?httpException.GetHttpCode() : 0; Server.ClearError(); Response.Redirect(String.Format("~/Error/Error?error={0}", error, exception.Message)); } }
protected void Application_Error(object s, EventArgs e) { try { Exception ex = Server.GetLastError(); if (ex != null && ex.GetType().Name == "HttpException") { HttpException exception = (HttpException)ex; if (exception.GetHttpCode() == 404) { Response.StatusCode = 404; } } Server.ClearError(); } catch (Exception ex) { } }
protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); HttpException httpException = exception as HttpException; if (!Request.IsLocal && httpException != null) { switch (httpException.GetHttpCode()) { case 500: Response.Redirect("~/error/500"); break; case 404: Response.Redirect("~/error/404"); break; } } }
void Application_Error(object sender, EventArgs e) { HttpException lastErrorWrapper = Server.GetLastError() as HttpException; if (lastErrorWrapper.GetHttpCode() == 404) { Server.Transfer("~/ErrorPage.html"); } Exception exc = Server.GetLastError(); string str = ""; str = exc.Message; string path = @"D:\AllErrors.txt"; File.WriteAllText(path, str); Server.Transfer("~/ErrorPage.html"); }
/// <summary> /// 不是每次请求都调用 /// 所有没有处理的错误都会导致这个方法的执行 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Application_Error(object sender, EventArgs e) { Exception lastError = Server.GetLastError(); if (lastError != null) { //异常信息 string strExceptionMessage = string.Empty; //对HTTP 404做额外处理,其他错误全部当成500服务器错误 HttpException httpError = lastError as HttpException; if (httpError != null) { //获取错误代码 int httpCode = httpError.GetHttpCode(); strExceptionMessage = httpError.Message; if (httpCode == 400 || httpCode == 404) { Response.StatusCode = 404; //跳转到指定的静态404信息页面,根据需求自己更改URL Response.WriteFile("~/Views/HttpError/404.html"); Server.ClearError(); return; } } strExceptionMessage = lastError.Message; /*----------------------------------------------------- * 此处代码可根据需求进行日志记录,或者处理其他业务流程 * ---------------------------------------------------*/ /* * 跳转到指定的http 500错误信息页面 * 跳转到静态页面一定要用Response.WriteFile方法 */ Response.StatusCode = 500; Response.WriteFile("~/Views/HttpError/500.html"); //一定要调用Server.ClearError()否则会触发错误详情页(就是黄页) Server.ClearError(); } }
protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); Response.Clear(); HttpException httpException = exception as HttpException; if (httpException != null) { string action; switch (httpException.GetHttpCode()) { case 404: // page not found action = "HttpError404"; Server.ClearError(); Response.Clear(); Response.Redirect("~/Error/FileNotFound"); break; case 401: // page not found action = "HttpError404"; Server.ClearError(); Response.Clear(); Response.Redirect("~/Error/Unauthorised"); break; default: // action = "General"; Server.ClearError(); Response.Clear(); Response.Redirect(String.Format("~/Error?message={0}", exception.Message)); break; } // clear error on server //Server.ClearError(); //Response.Redirect(String.Format("~/Error/General?message={0}", exception.Message)); } }
protected void Application_Error(object sender, EventArgs e) { return; Exception exception = Server.GetLastError(); Server.ClearError(); // Response.Redirect("~/Home/Error"); HttpException httpException = exception as HttpException; Response.Clear(); Server.ClearError(); var routeData = new RouteData(); routeData.Values["controller"] = "Error"; routeData.Values["action"] = "General"; routeData.Values["exception"] = exception; Response.StatusCode = 500; if (httpException != null) { Response.StatusCode = httpException.GetHttpCode(); switch (Response.StatusCode) { case 403: routeData.Values["action"] = "HttpError403"; break; case 404: routeData.Values["action"] = "HttpError404"; break; default: routeData.Values["action"] = "General"; break; } } IController errorsController = new ErrorController(); var rc = new RequestContext(new HttpContextWrapper(Context), routeData); errorsController.Execute(rc); }
void Application_Error(object sender, EventArgs e) { bool IsAjax = new HttpRequestWrapper(System.Web.HttpContext.Current.Request).IsAjaxRequest(); Exception exception = Server.GetLastError(); Response.Clear(); HttpException httpException = exception as HttpException; string action = "Error"; if (httpException != null) { switch (httpException.GetHttpCode()) { case 404: // page not found action = "HttpError404"; HttpContext.Current.Response.StatusCode = 404; HttpContext.Current.Response.StatusDescription = "Not Found"; break; default: break; } } else { HttpContext.Current.Response.StatusCode = 500; HttpContext.Current.Response.StatusDescription = "Error"; } // clear error on server Server.ClearError(); if (IsAjax) { HttpContext.Current.Response.SuppressFormsAuthenticationRedirect = true; } else { Response.Redirect(String.Format("~/Error/{0}/", action)); } }
protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); Response.Clear(); HttpException httpException = exception as HttpException; if (httpException != null) { int HttpCode = httpException.GetHttpCode(); // clear error on server Server.ClearError(); //Response.Redirect(String.Format("~/Project/{0}", action)); Response.Redirect(String.Format("~/Project/Error?HttpCode={0}&message={1}", HttpCode, exception.Message)); } }
protected void Application_Error(object sender, EventArgs e) { Exception exept = Server.GetLastError(); HttpException httpEx = exept as HttpException; if (httpEx.GetHttpCode() == 404) { Server.ClearError(); Response.Redirect("/Error/NotFound"); } else { HttpContext con = HttpContext.Current; var url = con.Request.Url.ToString(); _adding.AddNewError(url, exept.Message); Server.ClearError(); Response.Redirect("/Error/ServerError"); } }
protected void Application_Error(object sender, EventArgs e) { string errorMsg = "Global Error Key:{0} 發生例外網址:{1} HttpMethod:{2} 使用者:{3}"; Exception exception = Server.GetLastError(); HttpContext httpContext = HttpContext.Current; RouteData routeData = new RouteData(); HttpException httpException = exception as HttpException; string GuidKey = Math.Abs(exception.GetHashCode()).ToString(); string httpErrorCode = string.Empty; var ActionType = Request.HttpMethod; var UserName = string.IsNullOrWhiteSpace(httpContext.User.Identity.Name) ? "NaN" : httpContext.User.Identity.Name; if (httpException != null) { httpErrorCode = httpException.GetHttpCode().ToString(); } errorMsg = string.Format(errorMsg, GuidKey, Request.Url.ToString(), ActionType, UserName); routeData.Values.Add("controller", "Error"); routeData.Values.Add("error", GuidKey); switch (httpErrorCode) { case "404": routeData.Values.Add("action", "General"); break; case "500": routeData.Values.Add("action", "General"); break; default: routeData.Values.Add("action", "General"); break; } //TODO 在此處紀錄log //LibroLib.ShareMethod.PutLog("Global_Error", $"由{UserName}觸發{exception.GetType().FullName}"); //LibroLib.ShareMethod.PutLog("Global_Error", $"HttpMethod:{ActionType} Url:{RequestUrl} StatusCode{code}"); //LibroLib.ShareMethod.ExceptionLog("Global_Error", exception); Response.Clear(); Response.Redirect("~/Home/Index"); Server.ClearError(); }
public virtual ActionResult Index(string catchAll, HttpException exception) { var model = new ErrorModel(); var httpCode = exception.GetHttpCode(); switch (httpCode) { case 403: Response.StatusCode = model.ErrorNum = 403; model.Heading = Messages.Errors_Error403; model.Message = Messages.Errors_Error403Description; break; case 404: Response.StatusCode = model.ErrorNum = 404; model.Heading = Messages.Errors_Error404; model.Message = Messages.Errors_Error404Description; break; case 500: Response.StatusCode = model.ErrorNum = 500; model.Heading = Messages.Errors_Error500; model.Message = Messages.Errors_Error500Description; break; case 503: Response.StatusCode = model.ErrorNum = 503; model.Heading = Messages.Errors_Error503; model.Message = string.Format(Messages.Errors_Error503Description, Application.CloseReason); break; } Response.TrySkipIisCustomErrors = true; if (IsPartialNeeded) { return(Json(model, JsonRequestBehavior.AllowGet)); } return(View(model)); }
protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); Response.Clear(); HttpException httpex = ex as HttpException; RouteData data = new RouteData(); data.Values.Add("Controller", "Error"); if (httpex == null) { data.Values.Add("Action", "Index"); } else { switch (httpex.GetHttpCode()) { case 404: data.Values.Add("Action", "Error404"); break; case 405: data.Values.Add("Action", "Error405"); break; case 500: data.Values.Add("Action", "Error500"); break; default: data.Values.Add("Action", "General"); break; } Server.ClearError(); Response.TrySkipIisCustomErrors = true; } IController controller = new ErrorController(); controller.Execute(new RequestContext(new HttpContextWrapper(Context), data)); }
protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); RequestContext rc = ((MvcHandler)HttpContext.Current.CurrentHandler).RequestContext; bool _IsAjaxRequest = new HttpRequestWrapper(HttpContext.Current.Request).IsAjaxRequest(); //是否是 Ajax string act_name = rc.RouteData.Values["Action"].ToString(); //取得 Action 名稱 string control_name = rc.RouteData.Values["Controller"].ToString(); //取的 Controller 名稱 Response.Clear(); LogTool.SaveLogMessage(exception, "Application_End"); HttpException httpException = exception as HttpException; if (httpException != null) { string action; switch (httpException.GetHttpCode()) { case 404: // page not found action = "StatusCode404"; break; case 500: // server error action = "StatusCode500"; break; default: action = "General"; break; } // clear error on server Server.ClearError(); Response.Redirect(String.Format("~/Error/{0}/?message={1}", action, exception.Message)); } }
public override void OnException(HttpActionExecutedContext actionExecutedContext) { if (actionExecutedContext.Exception == null) { return; } HttpRequestMessage request = actionExecutedContext.Request; Exception exception = actionExecutedContext.Exception; string ip = actionExecutedContext.ActionContext.Request.GetClientIpAddress(); #if NET45 string user = actionExecutedContext.ActionContext.RequestContext.Principal.Identity.Name; #else string user = Thread.CurrentPrincipal.Identity.Name; #endif string msg = "User:{0},IP:{1},Message:{2}".FormatWith(user, ip, exception.Message); Logger.Error(msg, exception); if (actionExecutedContext.Exception is HttpException) { HttpException httpException = (HttpException)exception; actionExecutedContext.Response = request.CreateResponse((HttpStatusCode)httpException.GetHttpCode(), new Error { Message = exception.Message }); } else if (Mappings.ContainsKey(exception.GetType())) { HttpStatusCode httpStatusCode = Mappings[exception.GetType()]; actionExecutedContext.Response = request.CreateResponse(httpStatusCode, new Error { Message = exception.Message }); } else { actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(HttpStatusCode.InternalServerError, new Error { Message = exception.Message }); } }
protected void Page_Load(object sender, EventArgs e) { ex = (HttpException)Server.GetLastError(); int httpCode = ex.GetHttpCode(); // Filter for Error Codes and set text if (httpCode >= 400 && httpCode < 500) ex = new HttpException (httpCode, "Safe message for 4xx HTTP codes.", ex); else if (httpCode > 499) ex = new HttpException (ex.ErrorCode, "Safe message for 5xx HTTP codes.", ex); else ex = new HttpException (httpCode, "Safe message for unexpected HTTP codes.", ex); // Log the exception and notify system operators ExceptionUtility.LogException(ex, "HttpErrorPage"); // Fill the page fields exMessage.Text = ex.Message; exTrace.Text = ex.StackTrace; // Show Inner Exception fields for local access if (ex.InnerException != null) { innerTrace.Text = ex.InnerException.StackTrace; InnerErrorPanel.Visible = Request.IsLocal; innerMessage.Text = string.Format("HTTP {0}: {1}", httpCode, ex.InnerException.Message); } // Show Trace for local access exTrace.Visible = Request.IsLocal; // Clear the error from the server Server.ClearError(); }