我尝试根据请求网址的第一个文件夹段实现多租户。 为了隔离租户之间的cookie,我试图用不同的名称配置它们,但我很难弄清楚如何做到这一点。 目前我的代码是这样的:
foreach (SiteFolder f in allFolders)
{
PathString path = new PathString("/" + f.FolderName);
app.Map(path,
siteApp =>
{
// this commented line would normally configure the cookies but I'm trying to do it myself below
//siteApp.UseIdentity();
siteApp.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/" + f.FolderName + "/Account/Login");
options.LogoutPath = new PathString("/" + f.FolderName + "/Account/LogOff");
options.CookieName = f.FolderName + "-ext";
options.SlidingExpiration = true;
},
IdentityOptions.ExternalCookieAuthenticationScheme
);
siteApp.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/" + f.FolderName + "/Account/Login");
options.LogoutPath = new PathString("/" + f.FolderName + "/Account/LogOff");
options.CookieName = f.FolderName + "-tfr";
options.SlidingExpiration = true;
},
IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme
);
siteApp.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/" + f.FolderName + "/Account/Login");
options.LogoutPath = new PathString("/" + f.FolderName + "/Account/LogOff");
options.CookieName = f.FolderName + "-tf";
options.SlidingExpiration = true;
},
IdentityOptions.TwoFactorUserIdCookieAuthenticationScheme
);
siteApp.UseCookieAuthentication(options =>
{
options.LoginPath = new PathString("/" + f.FolderName + "/Account/Login");
options.LogoutPath = new PathString("/" + f.FolderName + "/Account/LogOff");
options.CookieName = f.FolderName + "-app";
options.SlidingExpiration = true;
},
IdentityOptions.ApplicationCookieAuthenticationScheme
);
});
}
但是包括我改变的cookie名称在内的所有选项都没有任何影响。
我也有点困惑,因为Identity中的某些内容得到了配置"通过依赖注入而不是IApplicationBuilder。我希望以前由DI配置的东西只是默认值,以后可以由IApplicationBuilder更改,但我不清楚如何。
在使用Identity时,是否有人可以解释如何更改cookie名称之类的内容?