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;
}
}
GetOwinContext Method (HttpContext) Gets the IOwinContext for the current 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.
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.
HttpContext is a type which has a static Current property that you're using to get the current context.
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>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With