c# - 在新租户的 OwinStartup 之后添加 Owin 管道中间件

标签 c# asp.net-mvc owin ws-federation openid-connect

我有一个 Multi-Tenancy 应用程序,其中每个租户都可以为 WsFed 或 OpenIdConnect 定义自己的 ClientID、权限等。所有租户都在 OwinStartup 中注册如下:

 public void Configuration(IAppBuilder app)
 {
    List<WsFederationAuthenticationOptions> WsFedTenantOptions = BuildWsFedTenantOptionsList();
    List<OpenIdConnectAuthenticationOptions> OpenIdConnectTenantOptions = BuildOpenIdConnectTenantOptionsList();

    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    app.UseCookieAuthentication(new CookieAuthenticationOptions() { CookieSecure = CookieSecureOption.Never });

    foreach (var WsFedTenantOption in WsFedTenantOptions)
        app.UseWsFederationAuthentication(WsFedTenantOption);

    foreach (var OpenIdConnectTenantOption in OpenIdConnectTenantOptions)
        app.UseOpenIdConnectAuthentication(OpenIdConnectTenantOption);

    ...
}

它通过 context.Authentication.Challenge(AuthenticationType) 切换使用哪个 STS。这工作得很好。

问题是,当新租户注册时,我如何访问 IAppBuilder 并添加新的 AuthenticationOptions 而无需应用程序池回收?

最佳答案

IAppBuilder在Startup后不存在,用于构建请求执行管道然后被丢弃。管道未设计为在启动后进行修改。

关于c# - 在新租户的 OwinStartup 之后添加 Owin 管道中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28955118/

相关文章:

c# - C# 中的重载运算符实际上是好的做法吗?

c# - 如何在 Xamarin.Forms 中使用 ReactiveUI 只执行一次命令?

c# - 按枚举描述排序

asp.net-mvc - 如何通过.net身份中的自定义属性查找用户?

c# - ASP Identity 和 Owin - token 生成

c# - .NET Core RedirectToAction 不重定向

c# 为较小的图像生成缩略图

asp.net - 从 ViewBag 设置文本输入的值? ASP.NET MVC5

asp.net-mvc - Chrome 没有在我的 OpenID Connect 工作流程 (ASP.NET OWIN) 中保存/返回 Nonce cookie

c# - 使用 SignalR 注入(inject) IPrincipal