asp.net core 自定义404等友好错误页面
Home控制器里:
[Route("Home/Error/{statusCode}")] public IActionResult Error(int statusCode) { return View(); }
Startup.cs的Configure方法里添加:
app.UseStatusCodePagesWithRedirects("/Home/Error/{0}");
创建视图Error.cshtml:
@{ ViewData["Title"] = "Error"; } <h2>Error</h2> <div>404</div>