asp.net-identity - 'ClaimsPrincipal' 不包含 'GetUserId' 的定义

标签 asp.net-identity dnx

前段时间,我使用 ASP.Net 5 Web 应用程序模板创建了一个项目。
我记得当时 build 的项目。

现在,当我尝试构建我创建的旧项目时,出现错误

Severity    Code    Description Project File    Line    Suppression State
Error   CS1061  'ClaimsPrincipal' does not contain a definition for 'GetUserId' 
and no extension method 'GetUserId' accepting a first argument of type 'ClaimsPrincipal' could be found
 (are you missing a using directive or an assembly reference?)  KGWebsite.DNX 4.5.1, KGWebsite.DNX Core 5.0 
E:\EShared\Dev2016\KG.Website\KGWebsite\src\KGWebsite\Controllers\Web\ManageController.cs   291 Active

当我使用相同的模板从头开始创建新项目时,新项目将构建。我在对两个项目之间的差异进行故障排除时遇到问题。

两者都使用 DNX4.5.1,它在解决方案资源管理器中显示为引用 Microsoft.AspNet.Identity (3.0.0-rc1-final)

当我在工作副本中钻取 Microsoft.AspNet.Http 的元数据时,我有
#region Assembly Microsoft.AspNet.Http.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// C:\Users\kirsten\.dnx\packages\Microsoft.AspNet.Http.Abstractions\1.0.0-rc1-final\lib\net451\Microsoft.AspNet.Http.Abstractions.dll
#endregion

在非工作副本中,我有
#region Assembly Microsoft.AspNet.Mvc.ViewFeatures, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// C:\Users\kirsten\.dnx\packages\Microsoft.AspNet.Mvc.ViewFeatures\6.0.0-rc1-final\lib\net451\Microsoft.AspNet.Mvc.ViewFeatures.dll
#endregion

我应该采取哪些步骤来纠正不起作用的项目?

最佳答案

GetUserId() 方法是在 System.Security.Claims 命名空间中实现的扩展方法。因此,要使用该方法,只需在类中添加命名空间:

using System.Security.Claims;

关于asp.net-identity - 'ClaimsPrincipal' 不包含 'GetUserId' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35281860/

相关文章:

asp.net - 如何尽早访问即将到来的 Asp.Net Identity 更改?

c# - 身份 2.0 _LoginPartial 名字

c# - dnxcore50 可以引用针对 .net4.5 编译的 nuget 包吗

asp.net-core - Modelbinder 在返回 null 时默认为 0 而不是 Controller 中设置的值

visual-studio-2015 - 类库项目中的目标框架 dnx451 或 net451

asp.net-core - Visual Studio代码: Failed to launch external program dotnet

razor - 从 ASP.net Core 2 中的 View 访问自定义 ApplicationUser 属性

c# - asp.net mvc中通过用户ID aspnet.Identity获取用户名

c# - 从 ASP.NET MVC 5 中的角色中删除用户

asp.net-core - project.json 中的“预构建”脚本不运行