My application runs ASP.NET Core RC2 , and I am confused about how middleware works for the status code and the exception handler.
My application is configured with the following middleware.
app.UseStatusCodePagesWithReExecute("/Error/Status/{0}"); app.UseExceptionHandler("/Error/ServerError");
The controller processes the view to be returned:
[HttpGet] public IActionResult Status(int id) { switch (id) { case 404: return View("404"); case 400: return View("400"); case 500: return View("500"); default: return View("501"); } } [HttpGet] public IActionResult ServerError() { return View(); }
When I navigate to an unknown URL, it will return 404 page , as expected, from the Status action.
When I go to the action that throws the exception, it will be moved to /Error/ServerError , not the 500 page from the Status action.
public IActionResult ThrowException() { throw new Exception(); }
If I go to an action that returns StatusCodeResult(500); , it will return 500 page from the Status action.
[HttpGet] public IActionResult Error500() { return new StatusCodeResult(500); }
What bothers me is that the console shows that both results return 500 (Internal Server Error) , but depending on how they are returned, they will be moved to another page based on middleware.

Why is this?
source share