赖素文
authored
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
namespace WebMvc.Controllers
{
/// <summary>
/// 错误页面展示
/// </summary>
public class ErrorsController : Controller
{
|
赖素文
authored
|
16
|
private readonly IWebHostEnvironment _env;
|
赖素文
authored
|
17
|
|
赖素文
authored
|
18
|
public ErrorsController(IWebHostEnvironment env)
|
赖素文
authored
|
19
20
21
22
23
24
25
26
27
28
29
30
|
{
_env = env;
}
[Route("errors/{statusCode}")]
public IActionResult CustomError(int statusCode)
{
var filePath = $"{_env.WebRootPath}/errors/{(statusCode == 404 ? 404 : 500)}.html";
return new PhysicalFileResult(filePath, new MediaTypeHeaderValue("text/html"));
}
}
}
|