title: Alternative to use HttpContext in System.Web for Owin
body: <p>ASP.NET authentication is now based on OWIN middleware that can be used on any OWIN-based host. ASP.NET Identity <strong>does not have any dependency on System.Web</strong>.</p>
  <p>I have an AuthorizeAttribute filter where I need to get the current user and add some properties to be retrieved later by action controllers.</p>
  <p>The problem is that I have to use the HttpContext which belongs to System.Web. Is there any alternative of HttpContext for Owin?</p>
  <pre class="lang-cs prettyprint-override"><code>public class WebApiAuthorizeAttribute : AuthorizeAttribute 
  {
      public override async Task OnAuthorizationAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
      {
          base.OnAuthorization(actionContext);
  
          Guid userId = new Guid(HttpContext.Current.User.Identity.GetUserId());
  
          ApplicationUserManager manager = new ApplicationUserManager(new ApplicationUserStore(new ApplicationDbContext())) { PasswordHasher = new CustomPasswordHasher() };
          ApplicationUser user = await manager.FindByIdAsync(userId);
  
          actionContext.Request.Properties.Add(&quot;userId&quot;, user.LegacyUserId);
      }
  }
  </code></pre>
  <p>Note: I found <a href="https://stackoverflow.com/questions/23814265/what-to-use-instead-of-httpcontext-when-using-owin-without-system-web">this question</a>, which seems a duplicate, but asks for a solution working for NancyFx project, which is not valid for me.</p>