我有许多托管在主域和子域上的应用程序:
网站 A,ASP.NET (.Net Core 2.0),网址为 www.example.com
网站 B,ASP.NET MVC (4.7 .net Framework),位于 site.example.com
网站 C,ASP.NET Identity (.Net Core 2.0),位于 account.example.com
网站 D,ASP.NET Webform(4.7 .net Framework),位于 file.example.com
我想在account.example.com上登录使用,经过身份验证后,用户将重定向到其他网站。他们将获得其他网站上角色的授权。
我正在尝试在这些网站之间共享 cookie,并且所有网站都托管在Azure Web App上。
我正在使用ASP.NET Identity (.Net Core 2.0)。我正在使用内置的 cookie 身份验证。
如何在所有应用程序中使用数据保护并在它们之间共享 cookie。
对于数据保护,我的代码是:
services.AddDataProtection()
.SetApplicationName("example")
.PersistKeysToFileSystem(new DirectoryInfo(@"%HOME%\ASP.NET\DataProtection-Keys"))
.SetDefaultKeyLifetime(TimeSpan.FromDays(14));
Run Code Online (Sandbox Code Playgroud)
对于 Cookie 身份验证,我的代码是:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
CookieDomain = ".example.com"
});
Run Code Online (Sandbox Code Playgroud) cookies webforms data-protection asp.net-identity asp.net-core