Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Aug 16, 2022, 1:21 AM EDT
Vishal YelveRank #178 · 13.6K reputationPosted Aug 16, 2022, 1:07 AM EDT
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.
Amit MohantyRank #112 · 20K reputationPosted Aug 16, 2022, 1:10 AM EDT
Vishal JoshiRank #377 · 6.7K reputationPosted Aug 16, 2022, 6:49 AM EDT