Do you have your StartUp.cs file configured to handle those error codes? If not, you'll need to do so, something like this:
app.UseStatusCodePages(async context =>
{
var response = context.HttpContext.Response;
switch (response.StatusCode)
{
case (int)HttpStatusCode.Unauthorized:
response.Redirect(URLHelper.AddParameterToUrl(ResHelper.GetString(ContentItemIdentifiers.LOGIN), "returnurl", context.HttpContext.Request.Path));
break;
case (int)HttpStatusCode.Forbidden:
if(String.IsNullOrEmpty(context.HttpContext.User.Identity.Name))
response.Redirect(URLHelper.AddParameterToUrl(ResHelper.GetString(ContentItemIdentifiers.LOGIN), "returnurl", context.HttpContext.Request.Path));
else
response.Redirect(ResHelper.GetString(ContentItemIdentifiers.PAGE_PERMISSION_DENIED));
break;
case (int)HttpStatusCode.NotFound:
response.Redirect(ResHelper.GetString(ContentItemIdentifiers.PAGE_NOT_FOUND));
break;
}
});