Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIDentity does not contain a definition for 'GetUserId'

I'm trying to use the VS2015 MVC controller and specifically GetUserID on User.Identity

i have seen a number of similar questions relating to this which state to add reference to Microsoft.AspNet.Identity, however as you can see that is referenced.

i assume i'm missing a package or something i just cannot figure it out

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Mvc;
using Web_Test.Models;  

namespace Web_Test.Controllers
{
    public class TestController : Controller
    {
    public TestController(UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager)
    {
        UserManager = userManager;
        SignInManager = signInManager;
    }
    public UserManager<ApplicationUser> UserManager { get; private set; }
    public SignInManager<ApplicationUser> SignInManager { get; private set; }

    public IActionResult Index()
    {
        //GetUserId() underlined in Red in VS2015
        //IIDentity does not contain a definition for 'GetUserId'
        string currentUserId = User.Identity.GetUserId();
        return View();
    }
}
}
like image 282
RoughPlace Avatar asked Dec 09 '14 23:12

RoughPlace


1 Answers

Adding the following worked for me. I also needed to add the NuGet Package Microsoft ASP.NET Identity Core mentioned by @Badri.

using Microsoft.AspNet.Identity; // NuGet: Microsoft ASP.NET Identity Core.
like image 131
Hans Vonn Avatar answered Oct 16 '22 23:10

Hans Vonn