What is missing from my HttpConfiguration instance that is present in GlobalConfiguration.Configuration?
GlobalConfiguration.cs Source Code from Codeplex
The main difference between when you create a new HttpConfiguration and one In GlobalConfiguration ...
public static class GlobalConfiguration { private static Lazy<HttpConfiguration> _configuration = CreateConfiguration();
Also when considering how UseWebAPi extension in WebApiAppBuilderExtensions.cs
public static IAppBuilder UseWebApi(this IAppBuilder builder, HttpConfiguration configuration) { if (builder == null) { throw new ArgumentNullException("builder"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } HttpServer server = new HttpServer(configuration); try { HttpMessageHandlerOptions options = CreateOptions(builder, server, configuration); return UseMessageHandler(builder, options); } catch { server.Dispose(); throw; } }
... the configuration completes with its own HttpServer , which overrides the default value used by GlobalConfiguration .
Looking through the documentation you included, I eventually came across this
For the standard IIS host, HttpConfiguration GlobalConfiguration.Configuration .
For self-hosting, the HttpConfiguration is your HttpSelfHostConfiguration instance.
For OWIN integration, the HttpConfiguration is the one you create in your application launch class and transition to the Web API middleware.
With standard IIS hosting, IIS handles authentication and user authentication, which it connects to the HttpConfiguration and the pipeline under the hood for you. When you new up HttpConfiguration yourself, you have no IIS benefits for authentication management for you, so your User remains null .
From your post, you indicate that you are using more than one HttpConfiguration instance that looks like you are trying to mix IIS and OWIN.
Looking at this question: OWIN Cookie Authentication
The answer shows that in the WebApi configuration, the next line ignores the cookie.
Commenting on this, cookie-based authentication work has been done.
UPDATE:
You specified...
Controllers work, routes too, the same WebApiConfig.cs file is used. However, User null in my API controllers is now
Take a look at ...
Combining authentication filters with host-level authentication
โHost-level authenticationโ is the authentication performed by the host (for example, IIS) before the request reaches the framework of the web API.
Often you can enable host-level authentication for the rest of your application, but disable it for your web API controllers. For example, a typical scenario is to enable authentication at the host level, but use token-based authentication for the web API.
To disable host-level authentication inside the web API pipeline, call config.SuppressHostPrincipal() in your configuration. This calls the Web API to remove the IPrincipal from any request that is part of the Web API . In fact, it does not "authenticate" the request.
public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.SuppressHostPrincipal();
If in your scenario you have the following in your web api configuration, this explains why your User always null . I suggest you comment on this or delete it all together.