I am use Umbraco v13.3.0 and uSkinned v6. I am trying to send 404 errors to a custom page I have created. I have added the Error404Collection property to the appsettings.json file, but it doesn’t seem to do anything. I have tried with ContentXPath, ContentId, and ContentKey.
I have a custom middleware class for catching and logging errors in custom code. I found I was able to redirect to my custom 404 page by doing something like this, but I don’t really like relying on JavaScript for this.
Note: context.Response.Redirect was also not working in the below class as I expected.
public async Task InvokeAsync(HttpContext context){
try
{
await _next(context);
if(context.Response.StatusCode == (int)HttpStatusCode.NotFound)
{
string redirecTo = "/my404";
_logger.LogError("trying to redirect (404) from " + context.Request.Path);
//context.Response.Redirect(redirecTo);
await context.Response.WriteAsync($"<script>window.location='{redirecTo}';</script>");
}
}
catch (Exception ex)
{
//log errors here
}
}
I feel like I am missing something. Does anyone have any suggestions on what I can try next?
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/114045-difficulties-with-custom-404-page