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

后端 未结 10 1711
暗喜
暗喜 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 05:46

    For Devs getting this error in Web API Project -

    The GetOwinContext extension method is defined in System.Web.Http.Owin dll and one more package will be needed i.e. Microsoft.Owin.Host.SystemWeb. This package needs to be installed in your project from nuget.

    Link To Package: OWIN Package Install Command -

    Install-Package Microsoft.AspNet.WebApi.Owin    
    

    Link To System.web Package : Package Install Command -

    Install-Package Microsoft.Owin.Host.SystemWeb
    

    In order to resolve this error you need to find why its occurring in your case. Please Cross check below points in your code -

    1. You must have reference to Microsoft.AspNet.Identity.Owin;

      using Microsoft.AspNet.Identity.Owin;

    2. Define GetOwinContext() Under HttpContext.Current as below -

       return _userManager1 ?? HttpContext.Current.GetOwinContext().GetUserManager();
      

      OR

      return _signInManager ?? HttpContext.Current.GetOwinContext().Get();
      

    Complete Code Where GetOwinContext() is used -

     public ApplicationSignInManager SignInManager
     {
       get
       {
        return _signInManager ?? HttpContext.Current.GetOwinContext().Get();
       }
        private set
        {
         _signInManager = value;
        }
      }
    

    Namespace's I'm Using in Code File where GetOwinContext() Is used

    using AngularJSAuthentication.API.Entities;
    using AngularJSAuthentication.API.Models;
    using HomeCinema.Common;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Web;
    using Microsoft.AspNet.Identity.Owin;
    using Microsoft.Owin.Security.DataProtection;
    

    I got this error while moving my code from my one project to another.

提交回复
热议问题