What is handle 404 error in ASP.NET Core?
Loading
What is handle 404 error in ASP.NET Core?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Aug 16, 2022, 5:21 AM
Vishal JoshiPosted Aug 16, 2022, 10:49 AM
Amit MohantyPosted Aug 16, 2022, 5:10 AM
Vishal YelvePosted Aug 16, 2022, 5:07 AM
A simple solution is to check for the HTTP status code 404 in the response. If found, you can redirect the control to a page that exists. The following code snippet illustrates how you can write the necessary code in the Configure method of the Startup class to redirect to the home page if a 404 error has occurred.
In Configure method of the startup class
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404)
{
context.Request.Path = "/Home";
await next();
}
})
Also please refer
https://dotnetblog.asphostportal.com/how-to-fix-404-error-in-asp-net-core-mvc/
https://www.infoworld.com/article/3545304/how-to-handle-404-errors-in-aspnet-coremvc.html#:~:text=A%20simple%20solution%20is%20to,a%20404%20error%20has%20occurred.