前一段时间,我使用ASP.Net 5 Web应用程序模板创建了一个项目。 我记得当时建的项目。
现在,当我尝试构建一个我创建的旧项目时,我有错误
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
我应采取哪些措施来纠正无效的项目?
答案 0 :(得分:4)
GetUserId()
方法是一种在System.Security.Claims
命名空间中实现的扩展方法。因此,要使用该方法,只需在类中添加命名空间:
using System.Security.Claims;