HttpContext.Current.User null with Web API v2 only project

My goal is to use IWA (Integrated Windows Authentication) with .NET Web API. I want to save the project as a web API project without MVC.

I created two projects in Visual Studio 2013 Premium:

  • I first chose ASP.NET Web Application with Authenticated Web API Pattern for Windows Authentication. This also includes ASP.NET MVC.
  • The second is the ASP.NET Web Application Empty template with basic links for the Web API.

The first one worked, I was able to get the AD / Windows ID of my account when called:

 HttpContext.Current.User

      

Second, I was unable to get the AD / Windows ID, I tried all of the following:

 - HttpContext.Current.User
 - User
 - RequestContext.Principal

      

What do I need to make a call from the web API (second project) to populate the user?

+3


source to share


1 answer


Web API v2 uses OWIN (Katana), to enable IWA with IIS you need to import Microsoft.Owin.Host.SystemWeb library. This uses IIS with an ASP.NET pipeline that populates User.

Instructions for setting up OWIN with Web API , notes:



  • This article is from 2013, since then Microsoft.Owin.Host.SystemWeb is no longer in preview, eg. you don't need "-pre" to install from NuGet.
  • Delete content inside Startup.cs configuration method.
+2


source







All Articles