如何在ASP.NET Core中获取中间件列表

编程入门 行业动态 更新时间:2024-10-25 08:20:51
本文介绍了如何在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>. 组件保存在 ApplicationBuilder 实现.但是,您可以使用一些反射魔术来烘焙扩展方法来确定实际的中间件类型,但这并不简单.

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中获取中间件列表

本文发布于:2023-11-05 09:47:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560512.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中间件   如何在   列表   NET   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!