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

后端 未结 10 1689
暗喜
暗喜 2020-12-04 05:04

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 t

相关标签:
10条回答
  • 2020-12-04 06:05

    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.

    0 讨论(0)
  • 2020-12-04 06:05

    Just using

    HttpContext.Current.GetOwinContext()

    did the trick in my case.

    0 讨论(0)
  • 2020-12-04 06:10

    To get UserManager in API

    return HttpContext.Current.GetOwinContext().GetUserManager<AppUserManager>();
    

    where AppUserManager is the class that inherits from UserManager.

    0 讨论(0)
  • 2020-12-04 06:10

    I had all the correct packages and usings, but had to built first before I could get GetOwinContext() to work.

    0 讨论(0)
提交回复
热议问题