skttl
10/02/2023, 8:11 AMapp.UseExceptionHandler("/500.html");
. It works as expected when working locally (in env.IsDevelopment()), but when deployed to an Azure Web App, I still get til empty default browser error page. Anyone tried this, and have some pointers? It's Umbraco 12. There is nothing in web.config taking over either.
I have this as the first part of the Configure method in Startup.cs:
cs
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/500.html");
app.Use(async (context, next) =>
{
// Detect and work around issue causing the error page not to be displayed:
if (context.Response.StatusCode == StatusCodes.Status500InternalServerError && context.Request.Path == "/500.html")
{
context.Features.Set<UmbracoRouteValues>(instance: null);
}
await next();
});
}
skttl
10/02/2023, 8:24 AMAmbert
10/02/2023, 8:36 AMAmbert
10/02/2023, 8:36 AMCodeSharePaul
10/02/2023, 8:39 AMskttl
10/02/2023, 8:40 AMAmbert
10/02/2023, 9:07 AMthrow new ArgumentOutOfRangeException("Error", "ThisIsAnError.");
and added the 500 file in wwwroot and added the `app.UseExpectionHandler("/500.html")
Getting the nice error
Added a simple SurfaceController with the same throw in it
Getting the nice errorskttl
10/02/2023, 9:08 AMAmbert
10/02/2023, 9:08 AMAmbert
10/02/2023, 9:08 AMskttl
10/02/2023, 9:26 AMcs
public class TestSurfaceController : SurfaceController
{
public TestSurfaceController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider) : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
{
}
[HttpGet]
public IActionResult TestGet()
{
throw new Exception("Test");
}
[HttpPost]
public IActionResult TestPost()
{
throw new Exception("Test");
}
}
Then I have my home page view:
cs
@{
Layout = null;
if (Context.Request.Query["throw"] == "ex")
{
throw new Exception("throw==ex");
}
}
@using (Html.BeginUmbracoForm<TestSurfaceController>("TestGet"))
{
<button>Get</button>
}
@using (Html.BeginUmbracoForm<TestSurfaceController>("TestPost"))
{
<button>Get</button>
}
<a href="/?throw=ex">throw from view</a>
Clicking the throw from view
link gets me my custom error page. None of the forms doesAmbert
10/02/2023, 9:27 AMAmbert
10/02/2023, 9:28 AMAmbert
10/02/2023, 9:28 AMskttl
10/02/2023, 9:28 AM@using (Html.BeginUmbracoForm<TestSurfaceController>("TestGet", FormMethod.Get))
{
<button>Get</button>
}
This works now... So I'm down to the post request 🙂Ambert
10/02/2023, 9:45 AMskttl
10/02/2023, 9:54 AMD_Inventor
10/02/2023, 12:44 PMskttl
10/02/2023, 12:46 PMD_Inventor
10/02/2023, 12:47 PMD_Inventor
10/02/2023, 12:49 PMcsharp
public class ServerErrorResponseCodeMiddleware
{
private readonly RequestDelegate _next;
public ServerErrorResponseCodeMiddleware(RequestDelegate next)
{
_next = next;
}
public Task InvokeAsync(HttpContext context)
{
context.Response.OnStarting(() =>
{
var exceptionPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
if (exceptionPathFeature is not null)
{
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
}
return Task.CompletedTask;
});
return _next(context);
}
}
In your case you omit context.Response.OnStarting
and instead perform your logic immediately.CodeSharePaul
10/02/2023, 1:39 PM