I have an ASP.NET Core application that does multi-tenanting based on the path. For example to log into tenant1 you would go do https://domain.name/tenant1 and to log in as tenant2 you would go do https://domain.name/tenant2. I have some middleware to get the tenant name from the request URI and pass that to the DbContext.
This works fine in normal use, but as an administator I can't log into more than one tenant at the same time because both of them store identity in the same .Aspnetcore.Identity.Application cookie for the same domain.
I know I can change the name of the cookie in Program.cs using
builder.Services.ConfigureApplicationCookie(options => options.Cookie.Name = "newcookiename")
but what I want to do is have it be different depending on the tenant, so tenant1's credentials would be stored in a .Aspnetcore.Identity.Application.tenant1 cookie and tenant2's credentials would be stored in a .Aspnetcore.Identity.Application.tenant2 cookie.
How can I do this?
CookieAuthenticationHandleris a singleton, so would only have a singleton instance of the options. IMHO write a customAuthenticationHandler, call the cookie handler, check for admin users, then use the path to create a ticket for anotherPrincipal? Build an admin only page to switch users...