我正在尝试根据其他一些问题here和here通过网络表单向用户添加声明,但在获取声明身份时我无法解析User
。我尝试将其更改为ApplicationUser
,但没有Identity属性。我该如何解决这个问题?
在我的用户模型中(称为ApplicationUser.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
namespace sideboob.Models
{
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
{
private readonly UserManager<ApplicationUser> _userManager;
public async void AddAsyncClaim(string id,string claimname,string claimvalue)
{
ApplicationUser user = await _userManager.FindByIdAsync(id);
var Identity = new ClaimsIdentity(User.Identity); //FAILS HERE
// Remove existing claim and replace with a new value
await _userManager.RemoveClaimAsync(user, Identity.FindFirst("AccountNo"));
await _userManager.AddClaimAsync(user, new Claim(claimname, claimvalue));
}
}
}
答案 0 :(得分:0)
试试这个:
using Microsoft.AspNetCore.Mvc;
我认为这可能只是一个导入。