What is URL of StackExchange.Exceptional errors for .NET Core 2 project?

306 Views Asked by At

I am try to use StackExchange.Exceptional in my .NET Core 2.1 project. I their documentation is not stated URL to accessing errors. I tried to google solution but only I can found is old URL to ASP.NET MVC 5 project which was Home/Errors which is not working in .NET Core. Any help?

1

There are 1 best solutions below

0
On

As far I know there is no default route. You can configure a route and name it to whaterever you want.

public sealed class ErrorController : ControllerBase
{
    // route will be /exceptions
    public async Task Exceptions() => await ExceptionalMiddleware.HandleRequestAsync(HttpContext);
}

Another thing you can do is to set it on the Configure method on the Startup class.

// route will be /exceptions
app.UseExceptional();
app.Map(new PathString("/exceptions"), action => action.Use(async (context, next) =>
{
    await ExceptionalMiddleware.HandleRequestAsync(context);
}));
app.UseMvc();

To make it visually better you can add the configuration in another class and import it to you Startup class

public static class ExceptionalConfiguration
{
    public static void UseExceptionalErrorPage(this IApplicationBuilder app)
    {
        // using exceptional to handle error pages
        app.Map(new PathString("/exceptions"), action => action.Use(async (context, next) =>
        {
            await ExceptionalMiddleware.HandleRequestAsync(context);
        }));
    }
}

// Startup class
app.UseExceptional();
app.UseExceptionalErrorPage();
app.UseMvc();