Request.GetOwinContext error in WebApi

I am trying to get OWin to work after this popular web api tutorial: http://bitoftech.net/2015/01/21/asp-net-identity-2-with-asp-net-web-api-2-accounts-management /

Now I'm stuck on the following Getter:

protected AppliationUserManager TengoUserManager { get { return _applicationUserManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>(); } } 

The problem is that Request.GetOwinContext () always returns null.

When I change getter to

  get { return _applicationUserManager ?? System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>(); } 

everything works perfectly. Now I wonder:

Is there a drawback to using HttpContext.Current instead of Request ?

Since HttpContext has OwinContext (), but Request does not: is it configurable? Launch code for my Owin authentication:

 public void Configuration(IAppBuilder app) { HttpConfiguration httpConfig=new HttpConfiguration(); app.CreatePerOwinContext(ApplicationContext.Create); app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); app.UseCors(CorsOptions.AllowAll); app.UseWebApi(httpConfig); config.MapHttpAttributeRoutes(); } 
+6
source share

Source: https://habr.com/ru/post/988390/


All Articles