asp.net-mvc - .Net Core Cookie 身份验证 - 用户收到错误声明
问题描述
我对托管在 IIS 中的 .net 核心 mvc 站点有一个非常奇怪的问题。
当用户使用此代码登录时:
var claimsIdentity = new ClaimsIdentity(
new List<Claim>() { new Claim(ClaimTypes.Role, "Admin", null), new Claim("Name", userName, null) }, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties
{
AllowRefresh = true,
ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(30),
IsPersistent = false,
};
HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
第一个用户登录时会显示他们的姓名。但是,当另一个用户登录时,他们会显示第一个用户名而不是他们自己的用户名。
我尝试过尝试所有 cookie 选项,但都没有成功,但这是我当前的配置:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options => {
options.Cookie.HttpOnly = false;
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/LogOff";
options.Cookie.IsEssential = true;
options.Cookie.MaxAge = new TimeSpan(0, 2, 0, 0, 0);
options.Cookie.SameSite = SameSiteMode.Strict;
options.Cookie.Name = "SITECODEHERE";
});
任何帮助将不胜感激,因为我确信我在某个地方犯了一个愚蠢的错误。
解决方案
经过大量调查,事实证明该问题是由我们的防火墙上的缓存引起的。
删除它解决了这个问题。
推荐阅读
- php - 带有条件的订单明细表下的文本
- graphql - Strapi GraphQL - 按项目计数子查询排序
- android - 带有 Smartlook SDK 的 Firebase crashlytics 未报告崩溃
- angular - 如何将 ngModel 值绑定到 select-searchable 选项中?
- python - Python 无法从列表中删除 None 值
- macos - 是否有任何 API 可以获取 macOS 中应用程序的全盘访问信息?
- assembly - 早期的 BIOS 如何使用 CALL?(跟进)
- java - 更改语言三星 S8+
- javascript - 将 192 场比赛的赛程分成 6 场比赛的周,没有重复的团队
- angular - Angular 8:监听不可访问组件中的内部元素