Hi @melon NG ,
I want to create a custom 404 page without the app.UseStatusCodePages.
To this issue, you can check Response.StatusCode in the Program.cs file (asp.net 6) or Startup.cs file (< asp.net 5), then return custom 404 error message or set the path of the custom error page. For example: if meet the 404 error, change the app.UseStatusCodePages();
as below:
//app.UseStatusCodePages();
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404)
{
await context.Response.WriteAsync("404 not found!");
// you can also use the following code to set the path of the custom error page.
//context.Request.Path = "/Home/Custom404Error";
//await next();
}
});
The result as below:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion