diff --git a/Bootstrap.Admin/Controllers/AccountController.cs b/Bootstrap.Admin/Controllers/AccountController.cs index c5fa9ed1..b6305932 100644 --- a/Bootstrap.Admin/Controllers/AccountController.cs +++ b/Bootstrap.Admin/Controllers/AccountController.cs @@ -84,11 +84,6 @@ namespace Bootstrap.Admin.Controllers /// /// The denied. [ResponseCache(Duration = 600)] - public ActionResult AccessDenied() - { - var returnUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].ToString(); - ViewBag.ReturnUrl = string.IsNullOrEmpty(returnUrl) ? Url.Content("~/Home/Index") : returnUrl; - return View(); - } + public ActionResult AccessDenied() => View("Error", ErrorModel.CreateById(403)); } } \ No newline at end of file diff --git a/Bootstrap.Admin/Controllers/HomeController.cs b/Bootstrap.Admin/Controllers/HomeController.cs index 3d7f0792..deef8261 100644 --- a/Bootstrap.Admin/Controllers/HomeController.cs +++ b/Bootstrap.Admin/Controllers/HomeController.cs @@ -30,27 +30,12 @@ namespace Bootstrap.Admin.Controllers [AllowAnonymous] public IActionResult Error(int id) { - var returnUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].ToString(); - var model = new ErrorModel() { ReturnUrl = string.IsNullOrEmpty(returnUrl) ? Url.Content("~/Home/Index") : returnUrl }; - model.Title = "服务器内部错误"; - model.Content = "服务器内部错误"; - model.Image = "error_icon.png"; - if (id == 0) - { - model.Content = "未处理服务器内部错误"; - } - else if (id == 404) - { - model.Title = "资源未找到"; - model.Content = "请求资源未找到"; - model.Image = "404_icon.png"; - } - else if (id == 403) - { - model.Title = "拒绝响应"; - model.Content = "请求资源的访问被服务器拒绝"; - model.ReturnUrl = Url.Content("~/Admin/Index"); - } + var model = ErrorModel.CreateById(id); + if (id != 403) + { + var returnUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].ToString(); + if (!string.IsNullOrEmpty(returnUrl)) model.ReturnUrl = returnUrl; + } return View(model); } } diff --git a/Bootstrap.Admin/Models/ErrorModel.cs b/Bootstrap.Admin/Models/ErrorModel.cs index c2ea8779..55d3dbfb 100644 --- a/Bootstrap.Admin/Models/ErrorModel.cs +++ b/Bootstrap.Admin/Models/ErrorModel.cs @@ -5,6 +5,11 @@ /// public class ErrorModel { + /// + /// + /// + public int Id { get; set; } + /// /// /// @@ -20,9 +25,51 @@ /// public string Image { get; set; } + /// + /// + /// + + public string Detail { get; set; } + /// /// /// public string ReturnUrl { get; set; } + + /// + /// + /// + /// + /// + public static ErrorModel CreateById(int id) + { + var model = new ErrorModel + { + Id = id, + Title = "服务器内部错误", + Content = "服务器内部错误", + Detail = "相关错误信息已经记录到日志中,请登录服务器或后台管理中查看", + Image = "~/Images/error_icon.png", + ReturnUrl = "~/Admin/Index" + }; + + switch (id) + { + case 0: + model.Content = "未处理服务器内部错误"; + break; + case 404: + model.Title = "资源未找到"; + model.Content = "请求资源未找到"; + model.Image = "~/Images/404_icon.png"; + break; + case 403: + model.Title = "未授权请求"; + model.Content = "您的访问受限!"; + model.Detail = "服务器拒绝处理您的请求!您可能没有访问此操作的权限"; + break; + } + return model; + } } } diff --git a/Bootstrap.Admin/Views/Account/AccessDenied.cshtml b/Bootstrap.Admin/Views/Account/AccessDenied.cshtml deleted file mode 100644 index 333edf2e..00000000 --- a/Bootstrap.Admin/Views/Account/AccessDenied.cshtml +++ /dev/null @@ -1,21 +0,0 @@ -@{ - ViewBag.Title = "未授权请求"; - Layout = "_Layout"; -} -@section css { - -} -@section javascript { - -} -
- -

您的访问受限!

-

服务器拒绝处理您的请求!您可能没有访问此操作的权限

-

登录 或者 返回首页

-
-

也可能是以下原因导致您没有权限

-

1. 没有登录,请登录后查看

-

2. 当前用户未获得此资源的相应权限,请联系管理员

-
-
\ No newline at end of file diff --git a/Bootstrap.Admin/Views/Home/Error.cshtml b/Bootstrap.Admin/Views/Home/Error.cshtml deleted file mode 100644 index 47646220..00000000 --- a/Bootstrap.Admin/Views/Home/Error.cshtml +++ /dev/null @@ -1,18 +0,0 @@ -@model ErrorModel -@{ - ViewBag.Title = Model.Title; - Layout = "_Layout"; -} -@section css { - -} -@section javascript { - -} -
- -

@Model.Content

-

相关错误信息已经记录到日志中,请登录服务器查看

-
- 返回首页 -
\ No newline at end of file diff --git a/Bootstrap.Admin/Views/Shared/Error.cshtml b/Bootstrap.Admin/Views/Shared/Error.cshtml new file mode 100644 index 00000000..06be13a9 --- /dev/null +++ b/Bootstrap.Admin/Views/Shared/Error.cshtml @@ -0,0 +1,25 @@ +@model ErrorModel +@{ + ViewBag.Title = Model.Title; + Layout = "_Layout"; +} +@section css { + +} +@section javascript { + +} +
+ +

@Model.Content

+

@Model.Detail

+

登录 或者 返回首页

+ @if (Model.Id == 403) + { +
+

也可能是以下原因导致您没有权限

+

1. 没有登录,请登录后查看

+

2. 当前用户未获得此资源的相应权限,请联系管理员

+
+ } +
\ No newline at end of file