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

what does getowincontext do
httpcontext does not contain a definition for current asp.net core
getowincontext .net core
microsoft.owin.host.systemweb nuget
httpcontext.current.getowincontext().authentication.challenge not working
owin httpcontext
no assembly found containing an owinstartupattribute.
asp net identity reference

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!

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.

ASP.NET Identity - HttpContext has no extension , ASP.NET Identity – HttpContext has no extension method for GetOwinContext. Posted by: admin November 10, 2017 Leave a comment. Questions:. 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

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.

ASP.NET Identity - HttpContext has no extension method , GetOwinContext() does not exist as an extension method on my HttpContext I am implementing the identity framework in class library. I have  ASP.NET Identity-HttpContext has no extension method for GetOwinContext (6) To get UserManager in API. return HttpContext.Current.GetOwinContext().GetUserManager<AppUserManager>(); where AppUserManager is the class that inherits from UserManager.

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?

'System.Web.HttpContext' does not contain a , HttpContext' does not contain a definition for 'GetOwinContext' whenever I debug my project. AspNet.Identity.Owin; using Microsoft.Owin.Security; using System. The GetOwinContext extension method is in the System. 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.

In my case adding Microsoft.AspNet.WebApi.Owin reference via nuget did the trick.

[Solved] 'Httpcontextbase' does not contain a definition for , Maybe that can help: SO: ASP.NET Identity - HttpContext has no extension method for GetOwinContext[^] Apparently you need a Microsoft. I have had an issue with Request.GetOwinContext().Authentication so many times now, I needed to create a post for my own purposes so I do not forget. The error I get

Make sure you installed the nuget package Microsoft.AspNet.Identity.Owin. Then add System.Net.Http namespace.

HttpContext.GetOwinContext() does not contain definition for, Hi Team I have this error and dont know how to fix it, please help me. AspNet.​Identity;; using Microsoft.AspNet.Identity.Owin;; using Microsoft.Owin. /asp-net-​identity-httpcontext-has-no-extension-method-for-getowincontext. Select the ASP.NET 4.6 Emtpy template, check the MVC combobox, make sure is is using “No Authentiction” and not to host it in the cloud. Hit OK. When the empty site is created it is a good time to add the OWIN startup class. This is a special class to be named Startup and to be placed under the root namespace of the web application.

Adding ASP.NET Identity to an Empty or Existing Web Forms Project , NET Identity support to your existing Web Forms project or a new is disabled and no authentication support is provided in this template. GetOwinContext(). These extension methods are the replacement for HttpContext. If you are deploying a new sub dependency, your are effectively deploying a new version of your 30 applications. You may not want to face it, but you are. Every single application is going to depend on that DLL to work properly. Has it been tested in each apps? Has it been compiled against each apps? What you are telling us is: "No.

What is the reference for HttpContext.GetOwinContext ()?, AspNet.Identity; using Microsoft.AspNet.Identity.Owin; using Microsoft.Owin.​Security GetOwinContext() is an extension method in System.Net. ASP.NET MVC 5 Membership impersonate specific user Tag: c# , asp.net , asp.net-mvc-5 , asp.net-identity There are many examples about impersonating a user in c# but the thing is you have to provide the domain, username and password of that user.

HttpContext GetOwinContext() outside Controller, HttpContext is the static class System.Web.HttpContext that is not HttpContextBase class. The right way is: If you don't find GetOwinContext extension method include this: 1. using Microsoft.AspNet.Identity.Owin; 

Comments
  • Thanks for figuring that one out: I'm using this tutorial asp.net/identity/overview/getting-started/… and it's a missing step
  • @tne - thank you for your comment... though I was hardly 'running around aimlessly' - i was following a tutorial from a trusted resource; from the asp.net site no-less. They didn't have that step in their tutorial (it's since been added) - also, the fact people are upvoting both this answer and the original Q also goes to indicate that I wasn't the only one with this issue.
  • @Darren, fair enough. (I do realize I could have worded that differently.)
  • Just for reference: nuget.org/packages/Microsoft.Owin.Host.SystemWeb/2.1.0
  • Don't know if it was from updating this reference, but I had to change up my assignment a little bit to var authenticationManager = HttpContext.Current.GetOwinContext().Authentication; (Current included where it wasn't there in the question).
  • Been trying this and just can't find it. - the GetOwinContext() i mean.
  • @Darren - I played with the sample template a little bit and may have the assembly you are missing. Looks like you will need to reference System.Web.Mvc from your class project. When commented out, that is what made HttpContext.GetOwinContext() become unknown (and not the Microsoft.Owin.Security assembly)
  • I've been trying to get this to work directly on a controller too - and again can't find it.
  • This should be the accepted answer. It's a subtle little thing.
  • This tripped me up. There is a public property HttpContext on the Controller class, so if you inherit from that, HttpContext.GetOwinContext() works as expected. If you inherit from ApiController though, there is no such property. Therefore, HttpContext will refer to the class, which will require you to use Current to access an instance of the class. So if you copy/paste code from a Controller to an ApiController and wonder why it doesn't work, this is the answer for you.