【发布时间】:2021-10-05 03:07:42
【问题描述】:
2 天以来,我一直在尝试阻止子域之间的 cookie 共享。当我登录一个特定的子(域)时,包括一级域,它也会将cookie直接设置到其他子(域)。
我想分离这些子(域)的登录过程。
我的 ConfigureServices 方法的 cookie 设置如下:
services.AddAuthentication(options =>
{
options.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
options.LoginPath = "/token";
options.Cookie.IsEssential = true;
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromDays(1);
options.Cookie.HttpOnly = true;
options.Cookie.Name = "AuthCookie";
options.Cookie.SameSite = SameSiteMode.Strict;
options.Cookie.SecurePolicy = CookieSecurePolicy.None;
})
我尝试了几个选项,例如 options.Cookie.Domain = "mydomain.com" 、 options.Cookie.Domain = "" 没有前导 .,但我仍然没有成功。
【问题讨论】:
-
您不能在根域
example.com上设置 cookie,也不希望在子域app.example.com上看到它。您需要在子域www.example.com上提供应用程序,然后它不会与另一个子域app2.example.com共享。 developer.mozilla.org/en-US/docs/Web/HTTP/…
标签: vue.js asp.net-core asp.net-web-api cookies jwt