ErrorController.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Abp.AspNetCore.Mvc.Controllers;
  2. using Abp.Web.Models;
  3. using Abp.Web.Mvc.Models;
  4. using Microsoft.AspNetCore.Diagnostics;
  5. using Microsoft.AspNetCore.Mvc;
  6. namespace VberAdmin.Controllers;
  7. public class ErrorController : AbpController
  8. {
  9. private readonly IErrorInfoBuilder _errorInfoBuilder;
  10. public ErrorController(IErrorInfoBuilder errorInfoBuilder)
  11. {
  12. _errorInfoBuilder = errorInfoBuilder;
  13. }
  14. public ActionResult Index(int statusCode = 0)
  15. {
  16. if (statusCode == 404)
  17. {
  18. return E404();
  19. }
  20. if (statusCode == 403)
  21. {
  22. return E403();
  23. }
  24. var exHandlerFeature = HttpContext.Features.Get<IExceptionHandlerFeature>();
  25. var exception = exHandlerFeature != null
  26. ? exHandlerFeature.Error
  27. : new Exception("Unhandled exception!");
  28. return View(
  29. "Error",
  30. new ErrorViewModel(
  31. _errorInfoBuilder.BuildForException(exception),
  32. exception
  33. )
  34. );
  35. }
  36. public ActionResult E403()
  37. {
  38. return View("Error403");
  39. }
  40. public ActionResult E404()
  41. {
  42. return View("Error404");
  43. }
  44. }