Skip to content

Commit 5dccb78

Browse files
Claudia Beatriz Murialdo Garroneclaudiamurialdoclaude
authored
fix: run TenantMiddleware before session load for Redis multitenant (#980)
UseAsyncSession eagerly calls Session.LoadAsync(), which resolves the tenant namespace from HttpContext.Items. Since TenantMiddleware ran after UseAsyncSession, the tenant id was unset at load time and fell back to "default", so per-subdomain sessions were read from the wrong Redis namespace and lost across requests. Move TenantMiddleware before the session middleware so the tenant id is set before the session is loaded. Co-authored-by: claudiamurialdo <33756655+claudiamurialdo@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e0ef479 commit 5dccb78

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,21 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
590590

591591
app.UseRouting();
592592
app.UseCookiePolicy();
593+
594+
ISessionService sessionService = GXSessionServiceFactory.GetProvider();
595+
// TenantMiddleware must run before the session is loaded: UseAsyncSession eagerly
596+
// calls Session.LoadAsync(), which resolves the tenant namespace from HttpContext.Items.
597+
// If the tenant id isn't set yet it falls back to "default", reading from the wrong
598+
// Redis namespace and losing per-subdomain session isolation.
599+
app.UseMiddleware<TenantMiddleware>();
600+
593601
if (Preferences.IsBeforeConnectEventConfigured())
594602
{
595603
app.UseMiddleware<EnableCustomSessionStoreMiddleware>();
596604
}
597605
app.UseAsyncSession();
598606
app.UseStaticFiles();
599607

600-
ISessionService sessionService = GXSessionServiceFactory.GetProvider();
601-
app.UseMiddleware<TenantMiddleware>();
602-
603608
ConfigureCors(app);
604609
ConfigureSwaggerUI(app, baseVirtualPath);
605610

0 commit comments

Comments
 (0)