【问题标题】:.Net Core Cookie Authentication - User Getting Wrong Claims.Net Core Cookie 身份验证 - 用户收到错误声明
【发布时间】:2019-08-05 10:56:48
【问题描述】:

我对托管在 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";
         });

任何帮助将不胜感激,因为我确信我在某个地方犯了一个愚蠢的错误。

【问题讨论】:

    标签: asp.net-mvc asp.net-core-2.0 .net-core-authorization core-authentication


    【解决方案1】:

    经过大量调查,事实证明该问题是由我们的防火墙上的缓存引起的。

    删除它解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2020-03-09
      • 2018-12-29
      • 2020-04-21
      • 2017-12-31
      • 2017-12-19
      • 2019-09-01
      • 2017-12-13
      • 1970-01-01
      • 2017-03-30
      相关资源
      最近更新 更多