Skip to content

Commit 585ee8e

Browse files
author
claudiamurialdo
committed
Always enable TenantMiddleware to support scenarios such as using database caching in Redis or storing sessions in Redis
1 parent 0e4f2ad commit 585ee8e

File tree

4 files changed

+4098
-4066
lines changed

4 files changed

+4098
-4066
lines changed

dotnet/src/dotnetcore/GxNetCoreStartup/SessionHelper.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,15 @@ public TenantMiddleware(RequestDelegate next)
6060

6161
public async Task Invoke(HttpContext context)
6262
{
63-
string host = context.Request.Host.Host;
64-
string subdomain = host.Split('.').FirstOrDefault();
65-
context.Items[AppContext.TENANT_ID] = subdomain;
63+
string host = context?.Request?.Host.Host ?? string.Empty;
64+
string subdomain;
65+
66+
if (!string.IsNullOrEmpty(host) && host.Contains('.'))
67+
{
68+
subdomain = host.Split('.').FirstOrDefault();
69+
if (!string.IsNullOrEmpty(subdomain))
70+
context.Items[AppContext.TENANT_ID] = subdomain;
71+
}
6672

6773
await _next(context);
6874
}

dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,7 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
505505
app.UseStaticFiles();
506506

507507
ISessionService sessionService = GXSessionServiceFactory.GetProvider();
508-
GxRedisSession gxRedisSession = sessionService as GxRedisSession;
509-
if (gxRedisSession != null && gxRedisSession.IsMultitenant)
510-
{
511-
app.UseMiddleware<TenantMiddleware>();
512-
}
508+
app.UseMiddleware<TenantMiddleware>();
513509

514510
ConfigureCors(app);
515511
ConfigureSwaggerUI(app, baseVirtualPath);

0 commit comments

Comments
 (0)