Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'System.Web.HttpContext' does not contain a definition for 'GetOwinContext'

I have the following error :'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' whenever I debug my project. this error is in the web API page, although it doesn't show an error in the default AccounController.cs and the nuget package is installed.what is missing?

using IdentitySample.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using System.Web;
using System.Threading.Tasks;
using task.Models;
using System.Globalization;
public ApplicationUserManager UserManager
    {
        get
        {
            return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();

        }
        private set
        {
            _userManager = value;
        }
    }
like image 902
mohammad Avatar asked Nov 03 '14 08:11

mohammad


People also ask

What is GetOwinContext?

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

What is HttpContext request?

The HttpContext encapsulates all the HTTP-specific information about a single HTTP request. When an HTTP request arrives at the server, the server processes the request and builds an HttpContext object. This object represents the request which your application code can use to create the response.

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 HttpContext MVC?

HttpContext is a type which has a static Current property that you're using to get the current context.


1 Answers

ok I found the solution since I already installed the nuget package all I have to do is the following:

  return _userManager ?? HttpContext.**current**.GetOwinContext().GetUserManager<ApplicationUserManager>();
like image 169
mohammad Avatar answered Oct 14 '22 07:10

mohammad