Middleware with Anonymous Inline Delegate & Decompression Support

Learn about implementing an anonymous inline delegate, handling specific routes, and outputting relevant information about chosen endpoints.

Implementing an anonymous inline delegate as middleware

A delegate can be specified as an inline anonymous method. We will register one that plugs into the pipeline after routing decisions for endpoints have been made. It will output which endpoint was chosen, as well as handling one specific route: /bonjour. If that route is matched, it will respond with plain text without calling any further into the pipeline to find a match:

Step 1: In the Northwind.Web project, in Program.cs, add statements before the call to UseHttpsRedirection to use an anonymous method as a middleware delegate, as shown in the following code:

Get hands-on with 1400+ tech skills courses.