Darren Darren - 1 year ago 272
C# Question

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

I have downloaded, and successfully ran the ASP.Net Identity sample from here:

I am now in the middle of implementing the ASP.Net Identity framework in my project and have ran into a problem, that has driven me mad all day...

does not exist as an extension method on my

I am implementing the identity framework in class library. I have installed all the latest (pre-release version) of the Identity framework and everything - apart from this - is working fine.

I have tried implementing the same code as the same direct in my controller, and find the same problem.

I'm clearly missing a reference somewhere, though I have no idea what..!..

The code-block that is killing me is:

private IAuthenticationManager AuthenticationManager
return HttpContext.GetOwinContext().Authentication;

I have added references to the following - tried these both in my class library and also direct on the controller, none of them work for me...

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security;
using Microsoft.Owin;
using System.Web;

... this is driving me up the wall....any idea?


I have checked the versions of Identity & OWIN in the sample, and have made sure I have the same versions in my solution.

More so, if I search the object browser on the sample for
I can find the method, however when I search for it in my solution it is nowhere to be found... I must have some library out of date, but can't find it!

Answer Source


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..

EDIT Although 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.