Reputation: 47
I have a question regarding sharing of cookies between multiple ASP.NET Core applications and Entity Framework.
I Have Two domains
www.servic2.com
www.servic1.com
I'am setting cookie in servic1 but need cookie on servic2.
I can't get the authentication to persist across both.
I have the startup.cs configured in the following way:
.AddAuthentication(options =>
{
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.SlidingExpiration = true;
options.LoginPath = "/Login";
options.LogoutPath = "/Logout";
//options.AccessDeniedPath = new PathString("/Home/Forbidden/");
//options.Cookie.Name = ".my.app1.cookie";
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
//Indicates whether the browser should allow the cookie to be attached to same-site requests only (SameSiteMode.Strict) or cross-site requests using safe HTTP methods and same-site requests (SameSiteMode.Lax).
options.Cookie.SameSite = SameSiteMode.Lax;
options.Events = new CookieAuthenticationEvents
{
OnValidatePrincipal = context =>
{
var cookieValidatorService = context.HttpContext.RequestServices.GetRequiredService<ICookieValidatorService>();
return cookieValidatorService.ValidateAsync(context);
}
};
});
Upvotes: 2
Views: 74