title: Map a route to a middleware class?
body: <p>Seems like this should be a straightforward question, but I've been unable to find a solution via Google.</p>
  
  <p>It seems pretty standard that in ASP.NET Core, <code>IHttpHandler</code> implementors are replaced by middleware classes. One nicety of the old system was that you could set up an HTTP handler to respond to a route, specified in the web.config.</p>
  
  <p>So, for instance, if my <code>IHttpHandler</code> implementor was named <code>FooHandler</code>, web.config would contain something like:</p>
  
  <pre><code>&lt;location path="foo"&gt;
      &lt;system.webServer&gt;
          &lt;handlers&gt;
              &lt;add name="FooHandler" path="*" verb="*" type="FooCompany.FooProduct.FooHandler, FooCompany.FooProduct"/&gt;
          &lt;/handlers&gt;
      &lt;/system.webServer&gt;
  &lt;/location&gt;
  </code></pre>
  
  <p>Is there a one-to-one replacement for routing like this in ASP.NET Core? How do I do this?</p>
  
  <p><strong>Edit</strong>: The new middleware class might look something like:</p>
  
  <pre><code>using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Http;
  using System.Threading.Tasks;
  
  namespace FooCompany.FooProduct.Middleware
  {
      public class FooMiddleware
      {
          private readonly RequestDelegate _next;
  
          public FooMiddleware(RequestDelegate next)
          {
              _next = next;
          }
  
          public async Task Invoke(HttpContext context)
          {
              context.Response.StatusCode = 200;
              await context.Response.WriteAsync("OK");
  
              await _next.Invoke(context);
          }
      }
  
      public static class FooMiddlewareExtensions
      {
          public static IApplicationBuilder UseFoo(this IApplicationBuilder builder)
          {
              return builder.UseMiddleware&lt;FooMiddleware&gt;();
          }
      }
  }
  </code></pre>