重构代码:增加ErrorModel,使用统一的Error视图,删除NotFound错误页面
This commit is contained in:
parent
0e9b2f7890
commit
d9eae9bac3
|
@ -20,6 +20,7 @@ namespace Bootstrap.Admin.Controllers
|
||||||
var url = DictHelper.RetrieveHomeUrl();
|
var url = DictHelper.RetrieveHomeUrl();
|
||||||
return url.Equals("~/Home/Index", System.StringComparison.OrdinalIgnoreCase) ? (IActionResult)View(new HeaderBarModel(User.Identity)) : Redirect(url);
|
return url.Equals("~/Home/Index", System.StringComparison.OrdinalIgnoreCase) ? (IActionResult)View(new HeaderBarModel(User.Identity)) : Redirect(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -29,8 +30,21 @@ namespace Bootstrap.Admin.Controllers
|
||||||
public IActionResult Error(int id)
|
public IActionResult Error(int id)
|
||||||
{
|
{
|
||||||
var returnUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].ToString();
|
var returnUrl = Request.Query[CookieAuthenticationDefaults.ReturnUrlParameter].ToString();
|
||||||
ViewBag.ReturnUrl = string.IsNullOrEmpty(returnUrl) ? Url.Content("~/Home/Index") : returnUrl;
|
var model = new ErrorModel() { ReturnUrl = string.IsNullOrEmpty(returnUrl) ? Url.Content("~/Home/Index") : returnUrl };
|
||||||
return id == 404 ? View("NotFound") : View();
|
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";
|
||||||
|
}
|
||||||
|
return View(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
namespace Bootstrap.Admin.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ErrorModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string Content { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string Image { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string ReturnUrl { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
using Bootstrap.DataAccess;
|
using Bootstrap.DataAccess;
|
||||||
using Bootstrap.Security.Filter;
|
using Bootstrap.Security.Filter;
|
||||||
using Longbow.Logging;
|
|
||||||
using Longbow.Web;
|
using Longbow.Web;
|
||||||
using Longbow.Web.SignalR;
|
using Longbow.Web.SignalR;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@{
|
@model ErrorModel
|
||||||
ViewBag.Title = "服务器内部错误";
|
@{
|
||||||
|
ViewBag.Title = Model.Title;
|
||||||
Layout = "_Layout";
|
Layout = "_Layout";
|
||||||
}
|
}
|
||||||
@section css {
|
@section css {
|
||||||
|
@ -9,9 +10,9 @@
|
||||||
<script src="~/js/error.js"></script>
|
<script src="~/js/error.js"></script>
|
||||||
}
|
}
|
||||||
<section class="error-wrapper">
|
<section class="error-wrapper">
|
||||||
<img src="~/images/error_icon.png" />
|
<img src="~/images/@Model.Image" />
|
||||||
<h1>服务器内部错误</h1>
|
<h1>@Model.Content</h1>
|
||||||
<h3>相关错误信息已经记录到日志中,请登录服务器查看</h3>
|
<h3>相关错误信息已经记录到日志中,请登录服务器查看</h3>
|
||||||
<br />
|
<br />
|
||||||
<a href="@ViewBag.ReturnUrl" target="_top">返回首页</a>
|
<a href="@Model.ReturnUrl" target="_top">返回首页</a>
|
||||||
</section>
|
</section>
|
|
@ -1,17 +0,0 @@
|
||||||
@{
|
|
||||||
ViewBag.Title = "资源未找到";
|
|
||||||
Layout = "_Layout";
|
|
||||||
}
|
|
||||||
@section css {
|
|
||||||
<link href="~/css/error.css" rel="stylesheet" />
|
|
||||||
}
|
|
||||||
@section javascript {
|
|
||||||
<script src="~/js/error.js"></script>
|
|
||||||
}
|
|
||||||
<section class="error-wrapper">
|
|
||||||
<img src="~/images/404_icon.png" />
|
|
||||||
<h1>请求资源未找到</h1>
|
|
||||||
<h3>相关错误信息已经记录到日志中,请登录服务器查看</h3>
|
|
||||||
<br />
|
|
||||||
<a href="@ViewBag.ReturnUrl" target="_top">返回首页</a>
|
|
||||||
</section>
|
|
Loading…
Reference in New Issue