简体   繁体   中英

Can I find the controller in HttpSys pipeline?

We have services using HttpSys to selfhost a http-listener. We use them to host API's using MVC and implementing our controllers with ControllerBase

Our pipeline looks something like this:

        app.UseMiddleware<LogRequests>();
        app.UseMiddleware<ValidateAuthentication>();
        app.UseMiddleware<FloodingProtector>();
        app.UseMiddleware<AdjustCors>();
        app.UseMiddleware<FilterOutput>();
        app.UseCors("AllowAll");
        app.UseMvc();

The LogRequests is our own middeware, where we log information about the request.

In that middleware I would like to understand which Controller the MVC middleware used to execute the request. The Controller has information about a counter with metrics. I need that information in the LogRequests middleware for updating counters.

Is it possible to get information from the MVC middleware about which Controller was used to execute the request?

There is an Items property on HttpContext which can be used to transport information from a controller back to the pipeline.

That was not usable in my case, as HttpContext is not available in the constructor, which is where I needed it.

Other than that, I don't think there is any good way to send information from Controller to pipeline

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM