Lars-Erik
03/14/2024, 1:47 PMIContentLastChanceFinder
, default renderer and whatnot, but it seems impossible to replace the builtin 404 placeholder page without resorting to a 302.
Anyone managed to do this? I just want to display a static html file...Jason
03/14/2024, 2:01 PMJason
03/14/2024, 2:06 PM~/umbraco/UmbracoWebsite/NotFound.cshtml
Lars-Erik
03/14/2024, 2:07 PMLars-Erik
03/14/2024, 2:08 PMD_Inventor
03/14/2024, 2:31 PMD_Inventor
03/14/2024, 2:31 PMJason
03/14/2024, 3:52 PMcsharp
//program.cs
//...
app.UseStatusCodePagesWithReExecute("/Errors/{0}.html");
app.UseUmbraco()
//...
Then just pop a static file at ~/wwwroot/Errors/404.html
.
For Umbraco, the simplest thing to do is to override the view that Umbraco uses for it's default 404s.
Add a new file at ~/umbraco/UmbracoWebsite/NotFound.cshtml
, this will overwrite the default one that ships with Umbraco (and will get called by Umbraco's built in middleware)
You can combine the two approaches like so with a NotFound.cshtml
that's a bit like this:
csharp
@using Umbraco.Extensions
@using Microsoft.AspNetCore.Hosting
@inject IWebHostEnvironment host
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<cache>
@Html.Raw(await System.IO.File.ReadAllTextAsync(host.MapPathWebRoot("/Errors/404.html")))
</cache>
Lars-Erik
03/14/2024, 7:59 PMLars-Erik
03/14/2024, 7:59 PMLars-Erik
03/14/2024, 8:10 PMLars-Erik
03/14/2024, 8:11 PMLars-Erik
03/14/2024, 8:12 PM