0

I am trying to add a claim to a user via a web form based on some other SO questions here and here, but I cant resolve User when getting the Claims Identity. I tried changing it to ApplicationUser but that didnt have the Identity property. How do I fix this?

In my User Model (Called 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));
        }
    }
}
Rilcon42
  • 9,584
  • 18
  • 83
  • 167

1 Answers1

0

Try this:

using Microsoft.AspNetCore.Mvc;

I think it might be just an Import.

Leonardo Henriques
  • 784
  • 1
  • 7
  • 22