Solarion
Honorary Master
- Joined
- Nov 14, 2012
- Messages
- 28,051
- Reaction score
- 17,804
Hello everyone. I am still digging through issues with an MVC project I have. I am able to get an 404 page displayed when navigating to an incorrect url.
However any exceptions thrown and I still get a 404 page instead of my 500 page. Both the 404 and 500 are pages I created with some prettier styling.
FYI I have been struggling to get this to work since 3PM. I have tried every site I could get my hands on, every piece of ExceptionHandlingMiddlware I could try I tried. I've done it all and to no avail because I have still not tried the one that works.
Here is my middlware.
And my home controller.
As I said, every single error I can produce always results in a 404 error even if I flippn switch the database off entirely, still 404. How would I get the Exception from the pipeline?
However any exceptions thrown and I still get a 404 page instead of my 500 page. Both the 404 and 500 are pages I created with some prettier styling.
FYI I have been struggling to get this to work since 3PM. I have tried every site I could get my hands on, every piece of ExceptionHandlingMiddlware I could try I tried. I've done it all and to no avail because I have still not tried the one that works.
Here is my middlware.
Code:
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseStatusCodePagesWithRedirects("/Home/ErrorStatusCode?code={0}");
}
And my home controller.
Code:
[Authorize]
public class HomeController : Controller
{
[AllowAnonymous]
public IActionResult ErrorStatusCode(int code)
{
if (code == 404)
{
return View("404");
}
return View("500");
}
public IActionResult Index()
{
return View();
}
}
As I said, every single error I can produce always results in a 404 error even if I flippn switch the database off entirely, still 404. How would I get the Exception from the pipeline?
Last edited: