【发布时间】:2015-02-08 00:55:47
【问题描述】:
我正在尝试使用 VS2015 MVC 控制器,特别是在 User.Identity 上使用 GetUserID
我看到了许多与此相关的类似问题,哪个状态要添加对 Microsoft.AspNet.Identity 的引用,但是正如您所看到的那样。
我假设我错过了一个包裹或一些我无法弄清楚的东西
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();
}
}
}
【问题讨论】:
-
身份验证模式是否设置为“表单”?
标签: c# asp.net-mvc visual-studio asp.net-core