正如它在标题中所说的那样我已经为注册用户分配了声明,我现在正试图在用户登录sql server中的UserClaims表中的应用程序时检索声明值,我觉得这有点难以做到,因为这是我第一次使用索赔.
寻找我们的方向来实现这一目标,提前谢谢你.
public async Task<IActionResult> Register(RegisterViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, UserRoleId = model.RoleId };
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
_logger.LogInformation("User created a new account with password.");
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);
await _signInManager.SignInAsync(user, isPersistent: false);
_logger.LogInformation("User created a new account with password.");
await addUserClaims(model.CusomterId, model.UserName);
return …Run Code Online (Sandbox Code Playgroud) claims-based-identity claims asp.net-core-identity asp.net-core-2.0
我一直在尝试在ASP.NET MVC和system.web中实现http上下文,它只是允许我使用HttpContext.Current来访问上下文.无论如何,我开始在StartUp类的configureService方法中注入IhttpcontextAccessor.我发布此帖以查看是否有人使用.Net Core 2.0实现了此功能.如果是这样,请随时分享知识.提前致谢.
services.AddSingleton<HttpContextAccessor, HttpContextAccessor>();
Run Code Online (Sandbox Code Playgroud)