I have many application which is hosted on main domain and sub domains:
网站A,ASP.NET(.Net Core 2.0),网址为www.example.com
网站B,site.example.com上的ASP.NET Webform(4.7 .net Framework)
account.example.com上的网站C,ASP.NET身份(.Net Core 2.0)
网站D,file.example.com上的ASP.NET Webform(4.7 .net Framework)
我想在 account.example.com 上登录使用,经过身份验证的用户将重定向到其他网站 . 他们将通过其他网站上的角色进行授权 .
我正在尝试在这些网站之间共享cookie,并且所有网站都在 Azure Web App 上托管 .
我正在使用 ASP.NET Identity (.Net Core 2.0) . 我正在使用内置的cookie身份验证 .
如何在所有应用程序中使用Data Protection并在其中共享cookie .
对于数据保护,我的代码是:
services.AddDataProtection()
.SetApplicationName("example")
.PersistKeysToFileSystem(new DirectoryInfo(@"%HOME%\ASP.NET\DataProtection-Keys"))
.SetDefaultKeyLifetime(TimeSpan.FromDays(14));
对于Cookie身份验证,我的代码是:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
CookieDomain = ".example.com"
});
1 回答
关于.Net Core,如果你想在几个站点之间共享你的cookie,你可以尝试以下来初始化它而不是UseCookieAuthentication:
当然,您需要为所有站点提供相同的ProtectionProvider路径 .