从Razor页面视图中的声明中获取数据

时间:2019-03-21 12:36:10

标签: c# asp.net-core

我在登录用户之前先存储数据

  var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role);
  identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, loginData.Username));
  identity.AddClaim(new Claim(ClaimTypes.Name, loginData.Username));
  identity.AddClaim(new Claim(ClaimTypes.Role, "Dev"));
  var principal = new ClaimsPrincipal(identity);
  await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = loginData.RememberMe });

现在我该如何打印角色或检查?

   @Context.User.Claims.Select(c => c.Value)

这不起作用

0 个答案:

没有答案