Asp.net core 在两个应用程序ASP.NET Core之间共享cooki

Asp.net core 在两个应用程序ASP.NET Core之间共享cooki,asp.net-core,cookies,core,sharing,Asp.net Core,Cookies,Core,Sharing,我有一个关于在多个ASP.NET核心应用程序和实体框架之间共享cookie的问题 我有两个多明 www.servic2.com www.servic1.com 我把cooki设置为服务1,但需要cooki设置为服务2 我无法使身份验证在两者之间都保持 我在下面配置了startup.cs .AddAuthentication(options => { options.DefaultChallengeScheme = Cook

我有一个关于在多个ASP.NET核心应用程序和实体框架之间共享cookie的问题 我有两个多明
www.servic2.com
www.servic1.com
我把cooki设置为服务1,但需要cooki设置为服务2 我无法使身份验证在两者之间都保持 我在下面配置了startup.cs

 .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);
                          }
                      };
                  });
.AddAuthentication(选项=>
{
options.DefaultChallengeScheme=CookieAuthenticationDefaults.AuthenticationScheme;
options.defaultsignnscheme=CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme=CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(选项=>
{
options.SlidingExpiration=true;
options.LoginPath=“/Login”;
options.LogoutPath=“/Logout”;
//options.AccessDeniedPath=新路径字符串(“/Home/probled/”);
//options.Cookie.Name=“.my.app1.Cookie”;
options.Cookie.HttpOnly=true;
options.Cookie.SecurePolicy=CookieSecurePolicy.SameAsRequest;
//指示浏览器应允许cookie仅附加到相同的站点请求(SameSiteMode.Strict)还是使用安全HTTP方法和相同的站点请求(SameSiteMode.Lax)附加到跨站点请求。
options.Cookie.SameSite=SameSiteMode.Lax;
options.Events=新建CookieAuthenticationEvents
{
OnValidatePrincipal=上下文=>
{
var cookieValidatorService=context.HttpContext.RequestServices.GetRequiredService();
返回cookieValidatorService.ValidateAsync(上下文);
}
};
});