简体   繁体   中英

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

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?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM