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();
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With