'Microsoft.Owin.IOwinContext' does not contain a definition for 'GetUserManager' and no extension method?

安稳与你 提交于 2019-12-03 10:52:56

问题


The following code is copied from the Asp.Net Identity 2.0 sample.

private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
    get
    {
        return // Error 
          _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
    }
    private set
    {
        _userManager = value;
    }
}

However it gets the following error?

Error 3 'Microsoft.Owin.IOwinContext' does not contain a definition for 'GetUserManager' and no extension method 'GetUserManager' accepting a first argument of type 'Microsoft.Owin.IOwinContext' could be found (are you missing a using directive or an assembly reference?)

Update:

The version 2 of Microsoft.AspNet.Identity.Owin.dll already exists in ...\packages\Microsoft.AspNet.Identity.Owin.2.0.1\lib\net45.

However, the view definition of HttpContext.GetOwinContext() are different between my project and the sample. The first three lines of my project are

#region Assembly Microsoft.Owin.Host.SystemWeb.dll, v2.0.0.0
// C:\......\packages\Microsoft.Owin.Host.SystemWeb.2.0.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll
#endregion

while the sample is

#region Assembly Microsoft.Owin.Host.SystemWeb.dll, v2.1.0.0
// C:\....\sample\packages\Microsoft.Owin.Host.SystemWeb.2.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll
#endregion

But I already updated all Owin Nuget packages to the newest version using Neget.


回答1:


The extension method was moved to a different namespace, try adding

using Microsoft.AspNet.Identity.Owin;


来源:https://stackoverflow.com/questions/23532964/microsoft-owin-iowincontext-does-not-contain-a-definition-for-getusermanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!