gpt4 book ai didi

c# - IIDentity 不包含 'GetUserId' 的定义

转载 作者:太空狗 更新时间:2023-10-29 20:49:11 25 4
gpt4 key购买 nike

我正在尝试使用 VS2015 MVC Controller ,特别是 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();
}
}
}

最佳答案

添加以下内容对我有用。我还需要添加 NuGet 包 Microsoft ASP.NET Identity Core @Badri.提到

using Microsoft.AspNet.Identity; // NuGet: Microsoft ASP.NET Identity Core.

关于c# - IIDentity 不包含 'GetUserId' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27390694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com