Interfaces

Project

ExceptionReporter

NuGet packageOwin.Framework.ExceptionReporter
GitHub sourceOwinFramework.ExceptionReporter

Home |  Readme

Catches exceptions thrown by downstream middleware and returns an exception report. Returns templated public apology or detailed technical information. Can optionally send email

This middleware adds the following behaviour to your website:

  • Wraps the downstream OWIN pipeline in a try/catch block.
  • When exceptions are caught, if they are of type HttpException then the Http status code and message from the exception are send back to the client as a valid http response.
  • For other kinds of execptions the middleware returns either a public apology page or detailed technical information. The public apology page is templated and the default template allows a message to be inserted. For many applications you will want to change the template to match the design of the rest of your site.
  • Optionally sends email with detailed technical information about the exception that occured.

Adding this middleware to the Owin pipeline

builder.Register(ninject.Get<OwinFramework.ExceptionReporter.ExceptionReporterMiddleware>())
    .As("Exception reporter")
    .ConfigureWith(config, "/owinFramework/middleware/exceptions");
The assumes that you are using Ninject as your IoC container, and followed the getting started walkthrough. If this is not the case then you will need to adjust the code to work in your application.

Default Configuration

The configuration below is the configuration you will get by default if you do not provide a configuration for this middleware.

{
   "owinFramework": {
      "middleware": {
         "exceptions": {
            "message": null,
            "template": null,
            "requiredPermission": null,
            "localHost": true,
            "emailAddress": null,
            "emailSubject": "Unhandled exception in web site"
         }
      }
   }
}

Configuration Notes

  • To send emails when unhandled exceptions are caught, configure a valid email address and configure the standard .Net email sender with SMTP details.
  • When "localHost" is set to "true", requests originating from the web server machine always result in detailed technical information.
  • To return detailed technical information only to centain users, install Identification and Authorization middleware then configure the "requiredPermission" to the code name of a permission that you configured in authorization.
  • To define the public apology message set the "message" property to a string.
  • To completely replace the public message with a page of your own design set the "template" property to the path of your template file.