Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. protected void Application_Error(object sender, EventArgs e)
  2. {
  3. var httpContext = ((HttpApplication)sender).Context;
  4. ExecuteErrorController(httpContext, Server.GetLastError());
  5. }
  6.  
  7. public static void ExecuteErrorController(HttpContext httpContext, Exception exception)
  8. {
  9. if (!exception.Message.Contains("NotFound") && !exception.Message.Contains("ServerError"))
  10. {
  11. var routeData = new RouteData();
  12. routeData.Values["area"] = "Administration";
  13. routeData.Values["controller"] = "Error";
  14. routeData.Values["action"] = "Insert";
  15. routeData.Values["exception"] = exception;
  16.  
  17. using (Controller controller = new ErrorController())
  18. {
  19. ((IController)controller).Execute(new RequestContext(new HttpContextWrapper(httpContext), routeData));
  20. }
  21. }
  22. }
  23.  
  24. public ActionResult Insert(Exception exception)
  25. {
  26. ErrorSignal.FromCurrentContext().Raise(exception);
  27. Server.ClearError();
  28. Response.Clear();
  29.  
  30. switch (Tools.GetHttpCode(exception)) // (int)HttpStatusCode.NotFound;
  31. {
  32. case 400:
  33. return RedirectToAction("BadRequest");
  34. case 401:
  35. return RedirectToAction("Unauthorized");
  36. case 403:
  37. return RedirectToAction("Forbidden");
  38. case 404:
  39. return RedirectToAction("NotFound");
  40. case 500:
  41. return RedirectToAction("ServerError");
  42. default:
  43. return RedirectToAction("DefaultError");
  44. }
  45. }
  46.  
  47. public ActionResult Unauthorized()
  48. {
  49. return View();
  50. }
  51. ...
  52.  
  53. //GlobalConfiguration.Configure(WebApiConfig.Register);
  54. //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  55.  
  56. Runtime Error
  57.  
  58. Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
  59.  
  60. Details: To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".
  61.  
  62.  
  63. <!-- Web.Config Configuration File -->
  64.  
  65. <configuration>
  66. <system.web>
  67. <customErrors mode="RemoteOnly"/>
  68. </system.web>
  69. </configuration>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement