The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ErrorController.cs 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Teknik.Areas.Error.ViewModels;
  7. using Teknik.Controllers;
  8. using Teknik.Filters;
  9. namespace Teknik.Areas.Error.Controllers
  10. {
  11. public class ErrorController : DefaultController
  12. {
  13. [TrackPageView]
  14. [AllowAnonymous]
  15. public ActionResult Exception(Exception exception)
  16. {
  17. ViewBag.Title = "Exception - " + Config.Title;
  18. ViewBag.Description = "Just a boring 'ol exception. Nothing to see here, move along.";
  19. if (Response != null)
  20. {
  21. Response.StatusCode = 500;
  22. Response.TrySkipIisCustomErrors = true;
  23. }
  24. ErrorViewModel model = new ErrorViewModel();
  25. model.Exception = exception;
  26. return View("/Areas/Error/Views/Error/Exception.cshtml", model);
  27. }
  28. [TrackPageView]
  29. [AllowAnonymous]
  30. public ActionResult General(Exception exception)
  31. {
  32. ViewBag.Title = "Http Exception - " + Config.Title;
  33. ViewBag.Description = "There has been a Http exception. Run!";
  34. if (Response != null)
  35. {
  36. Response.StatusCode = 500;
  37. Response.TrySkipIisCustomErrors = true;
  38. }
  39. ErrorViewModel model = new ErrorViewModel();
  40. model.Description = exception.Message;
  41. model.Exception = exception;
  42. return View("/Areas/Error/Views/Error/General.cshtml", model);
  43. }
  44. [AllowAnonymous]
  45. public ActionResult Http403(Exception exception)
  46. {
  47. ViewBag.Title = "403 - " + Config.Title;
  48. ViewBag.Description = "Access Denied";
  49. if (Response != null)
  50. {
  51. Response.StatusCode = 403;
  52. Response.TrySkipIisCustomErrors = true;
  53. }
  54. ErrorViewModel model = new ErrorViewModel();
  55. model.Exception = exception;
  56. return View("/Areas/Error/Views/Error/Http403.cshtml", model);
  57. }
  58. [AllowAnonymous]
  59. public ActionResult Http404(Exception exception)
  60. {
  61. ViewBag.Title = "404 - " + Config.Title;
  62. ViewBag.Description = "Uh Oh, can't find it!";
  63. if (Response != null)
  64. {
  65. Response.StatusCode = 404;
  66. Response.TrySkipIisCustomErrors = true;
  67. }
  68. ErrorViewModel model = new ErrorViewModel();
  69. model.Exception = exception;
  70. return View("/Areas/Error/Views/Error/Http404.cshtml", model);
  71. }
  72. [TrackPageView]
  73. [AllowAnonymous]
  74. public ActionResult Http500(Exception exception)
  75. {
  76. ViewBag.Title = "500 - " + Config.Title;
  77. ViewBag.Description = "Something Borked";
  78. if (Response != null)
  79. {
  80. Response.StatusCode = 500;
  81. Response.TrySkipIisCustomErrors = true;
  82. }
  83. ErrorViewModel model = new ErrorViewModel();
  84. model.Exception = exception;
  85. return View("/Areas/Error/Views/Error/Http500.cshtml", model);
  86. }
  87. }
  88. }