Interfaces

Project

NotFound

NuGet packageOwin.Framework.NotFound
GitHub sourceOwinFramework.NotFound

Home |  Readme

This middleware will return a 404 response always. It will place itself after all other middleware in the pipeline so that when no other middleware handled the request a 404 response will be returned to the client.

If you want this behaviour only on certain routes through the OWIN pipeline then you can configure this middleware only on those routes. You can also add multiple instances of this middleware to the OWIN pipeline to have different 404 templates for different routes. For example if you have an API that returns JSON, you might want the API to also return JSON in the 404 case.

For this to work efficiently you should configure output caching. Without output caching the .less file will be compiled on every request.

Adding this middleware to the Owin pipeline

 builder.Register(ninject.Get<OwinFramework.NotFound.NotFoundMiddleware>())
    .As("Not found")
    .ConfigureWith(config, "/owinFramework/middleware/notfound");    
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": {
         "notfound": {
            "documentationRootUrl": "/owin/notFound/config",
            "template": ""
         }
      }
   }
}

Configuration notes

  • You can set the documentationRootUrl to null or empty to disable this documentation in your production environment.
  • The template setting should be the path to an html file that is to be sent as the response. If you do not provide a template then the template embedded into the Not Found middleware assembly will be used. The setting you configure is passed to the MapPath() method so you can include ~ meaning the root folder of the website.