【发布时间】:2018-02-07 15:55:51
【问题描述】:
我有这个控制器
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
Console.WriteLine("GET Index");
throw new Exception();
}
// POST api/values
[HttpPost]
public void Post()
{
Console.WriteLine("POST Index");
throw new Exception();
}
}
GET 和 POST 请求都返回状态码 500。这是预期的行为。
但是当我添加app.UseExceptionHandler("/api/debug/error");
在 Startup.cs 文件中,POST 请求不再返回状态码 500,而是返回 404。GET 请求仍然正常工作,返回状态码为 500。
调试控制器
[Route("api/[controller]")]
public class DebugController : Controller
{
[HttpGet("error")]
public IActionResult Index()
{
return StatusCode(500,"Hello, World! From debug controller");
}
}
任何 idé 为什么添加 app.UseExceptionHandler("/api/debug/error"); 会使 POST 请求以这种方式运行?
可以在Here 找到重现此行为的 repo。
【问题讨论】:
-
您有一个 Get 错误,但没有 Post 错误操作。
标签: c# asp.net asp.net-mvc asp.net-core