ASP.NET MVC 3上的自定义错误页
这个问题已经回答了,这是对Gweebz的答复。
protected void Application_Error() { //while my project is running in debug mode if (HttpContext.Current.IsDebuggingEnabled && WebConfigurationManager.AppSettings["EnableCustomErrorPage"].Equals("false")){ Log.Logger.Error("unhandled exception: ", Server.GetLastError());}else{ try { var exception = Server.GetLastError(); Log.Logger.Error("unhandled exception: ", exception); Response.Clear(); Server.ClearError(); var routeData = new RouteData(); routeData.Values["controller"] = "Errors"; routeData.Values["action"] = "General"; routeData.Values["exception"] = exception; IController errorsController = new ErrorsController(); var rc = new RequestContext(new HttpContextWrapper(Context), routeData); errorsController.Execute(rc); } catch (Exception e) { //if Error controller failed for same reason, we will display static HTML error page Log.Logger.Fatal("failed to display error page, fallback to HTML error: ", e); Response.TransmitFile("~/error.html"); }}}
慕莱坞森
慕田峪9158850