title: Call controller and action from custom middleware
body: <p>I'm new to ASP.NET 5 and the middleware classes. What I'm trying to create is a middleware class that reads incoming URL requests. Based on that I either want to let it go through and do a normal Route lookup, or I want my middleware class to call a specific controller/action from my Web API class.</p>
  
  <p>What I currently have is the following. I think the comments in the code explains what I'm trying to achieve.</p>
  
  <pre><code>public class RouteMiddleware
  {
      private readonly RequestDelegate _next;
  
      public RouteMiddleware(RequestDelegate next)
      {
          _next = next;
      }
  
      public async Task Invoke(HttpContext httpContext)
      {
          if(httpContext.Request.QueryString.Value == "test")
          {
              // Call custom Controller / Action
              // Then, don't do any more route resolving, since we already have the right controller/action
          }
          else
          {
              // Continue like normal
              await _next.Invoke(httpContext);
          }
      }
  }
  </code></pre>
  
  <p>How can I do this in my middleware class?</p>