2

ユーザーにクレームを追加すると、クレーム情報がページに Cookie として記録されず、他のすべての要求で情報が失われます。なぜこれが起こるのですか?

    public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
    {
        if (ModelState.IsValid)
        {
            try
            {
                var authReq = new AuthenticationViewModel() { password = model.Password, username = model.UserName };
                var userInfo = await _dataService.AuthenticateAsync(authReq);


                var claims = new List<Claim>();
                claims.Add(new Claim("username", userInfo.user.userName));
                claims.Add(new Claim("AddtionalData", userInfo.AddtionalData));

                var user = ClaimsPrincipal.Current;

                var identity = user.Identities.Where(x => x.AuthenticationType == "Custom").FirstOrDefault();

                if (identity == null)
                    identity = new ClaimsIdentity(claims.ToArray(), "Custom");

                user.AddIdentity(identity);


                return RedirectToAction("Users", "Index");
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Invalid username or password.");
            }

        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }
4

1 に答える 1