如何在ASP.NET Core中获取中间件列表 [英] How to get a list of middlewares in ASP.NET Core

查看:288
本文介绍了如何在ASP.NET Core中获取中间件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取活动中间件的列表? 如何获取特定URL的中间件列表(每个URL可能已向管道添加了一组不同的中间件)?

How do I get a list of active middlewares? How do I get a list of middlewares for specific url (each url may have a different set of middlewares added to the pipeline)?

我想通过使用某些常见的构建器扩展(例如UseMvc()app.UseIdentity();

I would like to know which middlewares are being added by using some of the common builder extensions like UseMvc() or app.UseIdentity();

我知道我可以检查每个扩展的源代码.有运行时方法可以做到这一点吗?

I know I could check the source code of each extension. Is there a runtime method to get this?

推荐答案

不,您不能.当您将中间件添加到管道中时,它已解析为Func<RequestDelegate, RequestDelegate>. 组件保存在

No, you can't. When you add a middleware to the pipeline, it's resolved to a Func<RequestDelegate, RequestDelegate>. The components are saved in a private field in the ApplicationBuilder implementation. You could however bake an extension method with some reflection magic to determine the actual middleware type, but it's not trivial.

这篇关于如何在ASP.NET Core中获取中间件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆