Bakground: 我想在ASP.NET Core中开发一个多租户应用程序,并且一直在研究Ben Fosters Saaskit库,它似乎为多租户应用程序中的常见问题提供了很好的解决方案。
问题:
SaasKit有一个UsePerTenant
方法,根据当前租户的不同,每个请求可以执行不同的操作。
我的目标是使用UsePerTenant
方法结合通过依赖注入注入的不同IOptions
对象。这可以在身份验证中间件中使用,如
AddAuthentication().AddCookie(..).AddOpenIdConnect(...)
在Startup.cs中的ConfigureServices
方法中配置了
public class Startup
{
// Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
...
}
// Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
...
}
}
我不能使ASP.NET 2.0+中的身份验证中间件对每个请求使用不同的IOptions
个对象,因为Startup.cs文件中的ConfigureServices
方法仅在每个应用程序启动时运行一次,并且UsePerTenant
方法应该在ASP.NET管道中为每个传入/传出请求运行的Configure
方法中使用。{/ p>
问题:
如何基于当前租户在ConfigureServices
方法中动态更改cookie和OpenID Connect选项?
答案 0 :(得分:2)
答案 1 :(得分:2)
我找到了一种很好的方法来获取任何类型的ASP.NET Core选项的每个租户选项,包括cookie或openID Connect。我把它包装成一个名为Finbuckle.MultiTenant的框架。
它基本上归结为一个看起来像这样的设置:
services.AddMultiTenant().
WithInMemoryStore()).
WithRouteStrategy().
WithPerTenantOptionsConfig<CookieAuthenticationOptions>((o, tenantContext) => o.Cookie.Name += tenantContext.Id);
如果您感到好奇,请在此处查看我的更多信息:https://www.finbuckle.com/MultiTenant