在运行时将新的中间件注册到OWIN管道,而无需重新启动应用程序 [英] register new middleware to OWIN pipeline at runtime without restart application

查看:102
本文介绍了在运行时将新的中间件注册到OWIN管道,而无需重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用Startup类在OWIN Pipeline中添加了所有可用的中间件,以对项目中的用户进行身份验证.一切正常.但是如何在运行时启动后将中间件添加到OWIN Pipeline. 这样,管理员就可以使用UI输入新的身份验证服务器的详细信息,并按需注册新的身份验证服务器,而不会干扰正在运行的应用程序.

I have added all available middleware in OWIN Pipeline using Startup class to authenticate user in my project. It is working fine. But how can I add middleware to OWIN Pipeline after Startup at runtime. So that Admin can enter the details of new Authentication Server using UI and register new authentication server on demand without disturbing running application.

推荐答案

实际上,标准owin管道实现并非旨在在运行时进行修改.它有两个生命周期阶段:初始化(管道创建)和运行(服务请求). 解决问题的正确而明确的方法是使用在运行时支持配置修改的中间件.

Actually, standard owin pipeline implementation is not designed to be modified during runtime. It has two lifetime phase: init (pipeline creation) and running (serving requests). The right and clear approach for your problem is to use middlewares which are support config modification at runtime.

在您的情况下: 如果您使用Kentor.AuthServices lib进行身份验证,则此支持是开箱即用的.您只需要在启动时注册一个中间件实例,并且当您修改(添加或删除IdentityProviders)最初提供的KentorAuthServicesOptions实例时,所做的更改将立即由中间件使用.

In your case: If you use Kentor.AuthServices lib for authentication, then this support comes out of the box. You only need to register one middleware instance at startup, and when you modifiy (add or remove IdentityProviders) the KentorAuthServicesOptions instance that you provided originally, the changes will immediately be used by the middleware.

如果必须使用其他组件,则可以通过将现有的身份验证中间件包装到新的中间件中并在内部处理实例来自己构建此支持. (您可以创建一个用于处理配置的中间件,并在每个配置中依次调用auth中间件...等.)

If you have to use other components, you can build this support by yourself by wrapping the existing auth middlewares into a new one and handle the instances internally. (You can create a middleware which handles the config(s) and calls the auth middleware one-after-another with each config...etc.)

这篇关于在运行时将新的中间件注册到OWIN管道,而无需重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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