Add this to the middleware pipeline
app.UseStatusCodePages(new StatusCodePagesOptions()
{
HandleAsync = (ctx) =>
{
if (ctx.HttpContext.Response.StatusCode == 404)
{
ctx.HttpContext.Response.ContentType = Text.Html;
ctx.HttpContext.Response.WriteAsync(
$"<div style='text-align: center'><h1 style='margin-top: 100px'>My Server Is Working</h1></div>");
}
return Task.FromResult(0);
}
});
Tags
ASP .NET core