Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have downloaded, and successfully ran the ASP.NET Identity sample from here: https://github.com/rustd/AspnetIdentitySample

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

GetOwinContext() does not exist as an extension method on my HttpContext

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 {     get     {         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?

UPDATE

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

More so, if I search the object browser on the sample for GetOwinContext 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 I can't find it!

like image 934
Darren Wainwright Avatar asked Jan 15 '14 21:01

Darren Wainwright


People also ask

How can get HttpContext current in ASP.NET Core?

In ASP.NET Core, if we need to access the HttpContext in service, we can do so with the help of IHttpContextAccessor interface and its default implementation of HttpContextAccessor. It's only necessary to add this dependency if we want to access HttpContext in service.

What is GetOwinContext?

GetOwinContext Method (HttpContext) Gets the IOwinContext for the current request.


1 Answers

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

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.

like image 102
Darren Wainwright Avatar answered Sep 19 '22 19:09

Darren Wainwright