protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); string filePath = AppConfig.Instance.ExceptionLogFilePath; if (string.IsNullOrEmpty(filePath) == false) { // Log to local file if log file path is defined in web.config new FileLogger(filePath).WriteException(exception); } else { // Log by web service to staging pholio database ExceptionLogger.LogException(exception, "Global.asax"); } RouteData routeData = new RouteData(); routeData.Values.Add("controller", "Error"); routeData.Values.Add("action", "Http500"); routeData.Values.Add("exception", exception); // Clear the error on server. Server.ClearError(); // Avoid IIS7 getting in the middle Response.TrySkipIisCustomErrors = true; // Call target Controller and pass the routeData. IController errorController = new ErrorController(); errorController.Execute(new RequestContext( new HttpContextWrapper(Context), routeData)); }
public static ActionResult InvokeHttp404(HttpContextBase httpContext) { IController errorController = new ErrorController(); var errorRoute = new RouteData(); errorRoute.Values.Add("controller", "Error"); errorRoute.Values.Add("action", "Http404"); errorRoute.Values.Add("url", httpContext.Request.Url.OriginalString); errorController.Execute(new RequestContext( httpContext, errorRoute)); return new EmptyResult(); }