services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.Cookie.Name = "TestCookie1"; options.LoginPath = new PathString("/Account/Login"); options.AccessDeniedPath = new PathString("/Account/Denied"); }) .AddCookie(options => { options.Cookie.Name = "TestCookie2"; options.LoginPath = new PathString("/Account/Login"); options.AccessDeniedPath = new PathString("/Account/Denied"); });
.Net Core Cookie 认证,怎么写入两个 Cookie?上面这样写是不能运行的
Authentication Cookie 是在 HttpContext.SignInAsync() 时写入的,如果你想在 Authentication Cookie 中写入更多信息,可以通过添加 Claim 的方式
claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userId.ToString()));
如果想写入不同名称的 Cookie ,那只能通过 Response.Cookies
context.Response.Cookies.Append(cookieName, cookieValue, cookieOptions);
.Net Core Cookie 认证的时候写入多个Cookie 估计是做不到了。
需要另外的 cookie 就自己写吧,简单粗暴:
HttpContext.Response.Cookies.Append("cookie1", "value1");
Thx