Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nbarbettini/01030ef83df9d87452e60c0c65e4cf86 to your computer and use it in GitHub Desktop.
Save nbarbettini/01030ef83df9d87452e60c0c65e4cf86 to your computer and use it in GitHub Desktop.
Wire up custom exception handler with IHostingEnvironment in ASP.NET Core 1.1
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// other code...
var hostingEnvironment = app.ApplicationServices.GetRequiredService<IHostingEnvironment>();
app.UseExceptionHandler(new ExceptionHandlerOptions
{
ExceptionHandler = new JsonExceptionMiddleware(hostingEnvironment).Invoke
});
app.UseMvc();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment