在 Blazor WebAssembly 中为子域配置了 Abp MultiTenancy 现在做什么?

问题描述 投票:0回答:1

我在客户端的 WebAssembly 应用程序的客户端和服务器中配置了子域多租户,例如输入 url 是

val = "https://en.api.localhost.com:44367"
我在客户端 Program.cs 上配置它,如下所示:

string val = await SubDomainTenant.GetApiServerAuthorityWithTenantSubDomain(builder, serviceProvider); // = https://en.api.localhost.com:44367
builder.Services.Configure<AbpRemoteServiceOptions>(async options =>
{
    options.RemoteServices.Default = new RemoteServiceConfiguration(val);
});

在服务器中:

builder.Services.Configure<AbpTenantResolveOptions>(options =>
{
    options.AddDomainTenantResolver(builder.Configuration["App:SelfUrl"]);
});

我在客户端的配置是:

"App": {
  "SelfUrl": "https://{0}.localhost.com:44367"
},
"RemoteServices": {
  "Default": {
    "BaseUrl": "https://{0}.api.localhost.com:44367"
  }
}

在服务器中:

"RootUrl": "https://{0}.localhost.com:44367",
"App": {
  "SelfUrl": "https://{0}.api.localhost.com:44367",
  "SelfUrlWithoutTenant": "https://api.localhost.com:44367",
  "CorsOrigins": "https://*.localhost.com,http://*.localhost.com:45144,https://*.localhost.com:44367,http://localhost.com:45144,https://localhost.com:44367"
}

应用程序可以运行,但是与之前的状态有什么不同?我仍然这样称呼我的服务器:

var result = await httpClient.GetStringAsync("api/account/getkeyiv");

在服务器中,请求以以下内容开头:

服务器上的 HttpContext.Request:

https://en.localhost.com:44367/api/account/getkeyiv

与常规请求有什么区别?

我在客户端 Program.cs (相关部分)中有这个:

//

val = "https://en.api.localhost.com:44367"

string val = await SubDomainTenant.GetApiServerAuthorityWithTenantSubDomain(builder, serviceProvider);
builder.Services.Configure<AbpRemoteServiceOptions>(options =>
{
    options.RemoteServices.Default = new RemoteServiceConfiguration(val);
});

var host = builder.Build();

CultureInfo culture;

Settings settings = await host.Services.GetRequiredService<Task<Settings>>();
var tenant = SubDomainTenant.GetTenantName(builder.HostEnvironment.BaseAddress);
if (tenant != null)
    tenant = tenant.Substring(0, tenant.IndexOf('.'));
if (tenant != null)
{    
    culture = new CultureInfo(tenant);
}
else
{    
    culture = new CultureInfo("en");
    var configUrl = settings.App.SelfUrl;
    var address = configUrl.Replace("{0}", tenant);
    Uri uri1 = new Uri(address);
    navigator.NavigateTo(address, true);
}
subdomain blazor-webassembly multi-tenant abp
1个回答
0
投票

DomainTenantResolver 的要点是它将从 URL 的第一段推断租户。

如果没有这个,您的租户/客户将需要转到登录页面,然后使用“更改租户”选项在登录之前设置其站点,否则他们将尝试登录主机(主管理员),这可能是他们会无权访问。这不是适合生产的用户体验,因此使用 DomainTenantresolver - 您的客户只需访问 mycustomer.myapp.com - 如果在服务器和身份(如果分层)项目上进行设置,它可以确保请求与该租户绑定,确保其数据的正确隔离。您还可以做一些事情,例如在其登陆和身份页面上定制品牌等。

© www.soinside.com 2019 - 2024. All rights reserved.