增加功能:增加404错误处理

This commit is contained in:
Argo-MacBookPro 2018-06-11 13:51:50 +08:00
parent 0320b68d5d
commit 4f9894d5bb
5 changed files with 22 additions and 2 deletions

View File

@ -9,6 +9,7 @@
<PackageReference Include="Bootstrap.Security.Mvc" Version="1.0.0" />
<PackageReference Include="Longbow.Web" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
</ItemGroup>
<ItemGroup>

View File

@ -22,11 +22,12 @@ namespace Bootstrap.Admin.Controllers
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[AllowAnonymous]
public ActionResult Error()
public IActionResult Error(int id)
{
return View();
return id == 404 ? View("NotFound") : View();
}
}
}

View File

@ -62,6 +62,7 @@ namespace Bootstrap.Admin
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStatusCodePagesWithReExecute("/Home/Error/{0}");
app.UseCors(builder => builder.WithOrigins(Configuration["AllowOrigins"].Split(',', StringSplitOptions.RemoveEmptyEntries)).AllowAnyHeader().AllowAnyMethod().AllowCredentials());
app.UseStaticFiles();
app.UseAuthentication();

View File

@ -0,0 +1,17 @@
@{
ViewBag.Title = "资源未找到";
Layout = "~/Views/Shared/_Root.cshtml";
}
@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="~/Home/Index" target="_top">返回首页</a>
</section>

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB