重构代码:删除ErrorViewModel
This commit is contained in:
parent
ad1081b6fc
commit
e01bd5d477
|
@ -1,7 +1,6 @@
|
|||
using Bootstrap.Client.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Bootstrap.Client.Controllers
|
||||
{
|
||||
|
@ -26,7 +25,7 @@ namespace Bootstrap.Client.Controllers
|
|||
[AllowAnonymous]
|
||||
public IActionResult Error(int id)
|
||||
{
|
||||
return id == 404 ? View("NotFound") : View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
return id == 404 ? View("NotFound") : View();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
namespace Bootstrap.Client.Models
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ErrorViewModel
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string RequestId { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
||||
}
|
|
@ -1,23 +1,17 @@
|
|||
@model ErrorViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
Layout = "_Root";
|
||||
@{
|
||||
ViewBag.Title = "服务器内部错误";
|
||||
Layout = "_Layout";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
@section css {
|
||||
<link href="~/css/error.css" rel="stylesheet" />
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
|
||||
</p>
|
||||
@section javascript {
|
||||
<script src="~/js/error.js"></script>
|
||||
}
|
||||
<section class="error-wrapper">
|
||||
<img src="~/images/error_icon.png" />
|
||||
<h1>服务器内部错误</h1>
|
||||
<h3>相关错误信息已经记录到日志中,请登录服务器查看</h3>
|
||||
<br />
|
||||
<a href="~/Home/Index" target="_top">返回首页</a>
|
||||
</section>
|
Loading…
Reference in New Issue