ASP.NET Identity - HttpContext has no extension method for GetOwinContext ASP.NET Identity - HttpContext has no extension method for GetOwinContext asp.net asp.net

ASP.NET Identity - HttpContext has no extension method for GetOwinContext


ARGH!

I found it... I didn't have an extra package, called Microsoft.Owin.Host.SystemWeb

Once i searched and installed this, it worked.

Now - i am not sure if i just missed everything, though found NO reference to such a library or package when going through various tutorials. It also didn't get installed when i installed all this Identity framework... Not sure if it were just me..

EDITAlthough it's in the Microsoft.Owin.Host.SystemWeb assembly it is an extension method in the System.Web namespace, so you need to have the reference to the former, and be using the latter.


I believe you need to reference the current HttpContext if you are outside of the controller. The MVC controllers have a base reference to the current context. However, outside of that, you have to explicitly declare you want the current HttpContext

return HttpContext.Current.GetOwinContext().Authentication;

As for it not showing up, a new MVC 5 project template using the code you show above (the IAuthenticationManager) has the following using statements at the top of the account controller:

using System.Threading.Tasks;using System.Web;using System.Web.Mvc;using Microsoft.AspNet.Identity;using Microsoft.AspNet.Identity.EntityFramework;using Microsoft.Owin.Security;using WebApplication2.Models;

Commenting out each one, it appears the GetOwinContext() is actually a part of the System.Web.Mvc assembly.


After trial and error comparing the using statements of my controller and the Asp.Net Template controller

using System.Web;

Solved the problem for me.You are also going to need to add:

using Microsoft.AspNet.Identity;using Microsoft.AspNet.Identity.Owin;

To use GetUserManager method.

Microsoft couldn't find a way to resolve this automatically with right click and resolve like other missing using statements?