24

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.

ca9163d9
  • 27,283
  • 64
  • 210
  • 413
  • possible duplicate of [ASP.Net WebAPI can't find Request.GetOwinContext](http://stackoverflow.com/questions/22598567/asp-net-webapi-cant-find-request-getowincontext) – Casey May 08 '14 at 04:56
  • 1
    `GetOwinContext()` works fine in my code though. `GetUserManager()` has problem. – ca9163d9 May 08 '14 at 05:18
  • 1
    Did you follow the steps specified here under "Download this release"? http://blogs.msdn.com/b/webdev/archive/2014/03/20/test-announcing-rtm-of-asp-net-identity-2-0-0.aspx – Kevin Junghans May 08 '14 at 13:39
  • @KevinJunghans Yes, I following it for upgrading my project. I remember there was some errors at beginning and I did retry. – ca9163d9 May 08 '14 at 14:49
  • 1
    Are you in a Controller or an ApiController? – Marc Jun 02 '14 at 18:56

1 Answers1

83

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

using Microsoft.AspNet.Identity.Owin;
Hao Kung
  • 28,040
  • 6
  • 84
  • 93