从自定义中间件调用控制器和操作

Viv*_*ndi 5 c# middleware asp.net-core-mvc asp.net-core

我是ASP.NET 5和中间件类的新手.我正在尝试创建的是一个中间件类,它读取传入的URL请求.基于此,我要么让它通过并进行正常的路由查找,或者我希望我的中间件类从我的Web API类调用特定的控制器/操作.

我现在拥有的是以下内容.我认为代码中的注释解释了我想要实现的目标.

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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能在我的中间件类中执行此操作?