title: proper implementation of "windows" authentication in web api?
body: <p>I've created a Web Api 2 app which will only be used on the corporate network. I've read about Windows authentication in Web API so it seems to be possible. But I need to figure out the proper implementation for this. I've included the following xml in my Web.config:</p>
  
  <pre><code>&lt;system.web&gt;
    &lt;authentication mode="Windows" /&gt;   
  &lt;/system.web&gt;
  </code></pre>
  
  <p>I seem to remember some type of event hook in old school webforms app. Something like BeginRequest() where a security check could be made before rendering a page. I included the following line of code as the first line in one of my controller methods but the returned value appears to just be an empty object without any meaningful info:</p>
  
  <pre><code>var identity = HttpContext.Current.User.Identity as WindowsIdentity;
  </code></pre>
  
  <p>Does Web API 2 support Windows authentication?  Am I missing a step?  Should Windows authentication work if I submit a general request from Postman for testing?  I also tried this code but got a similar empty object:</p>
  
  <pre><code>var x = RequestContext.Principal;
  </code></pre>
  
  <p>I vaguely recall an IIS setting like "Enable Integrated Security." Can you please specify the exact setting?  And would I be able to accomplish this if I'm running the app on IIS Express?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I followed the steps for IIS Express mentioned in one of the answers below but the code samples that I provided in my original post still didn't get a populated user object. I also updated applicationhost.config file to turn off anonymous authentication:</p>
  
  <pre><code>&lt;anonymousAuthentication enabled="false" userName="" /&gt;
  </code></pre>
  
  <p>After I made that updated I resubmitted my test request via Postman but I get the following error:</p>
  
  <pre><code>    &lt;h3&gt;HTTP Error 401.2 - Unauthorized&lt;/h3&gt;
      &lt;h4&gt;You are not authorized to view this page due to invalid authentication headers.&lt;/h4&gt;
  &lt;/div&gt;
  &lt;div class="content-container"&gt;
      &lt;fieldset&gt;
          &lt;h4&gt;Most likely causes:&lt;/h4&gt;
          &lt;ul&gt;
              &lt;li&gt;No authentication protocol (including anonymous) is selected in IIS.&lt;/li&gt;
              &lt;li&gt;Only integrated authentication is enabled, and a client browser was used that does not support integrated authentication.&lt;/li&gt;
              &lt;li&gt;Integrated authentication is enabled and the request was sent through a proxy that changed the authentication headers before they reach the Web server.&lt;/li&gt;
              &lt;li&gt;The Web server is not configured for anonymous access and a required authorization header was not received.&lt;/li&gt;
              &lt;li&gt;The "configuration/system.webServer/authorization" configuration section may be explicitly denying the user access.&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/fieldset&gt;
  &lt;/div&gt;
  &lt;div class="content-container"&gt;
      &lt;fieldset&gt;
          &lt;h4&gt;Things you can try:&lt;/h4&gt;
          &lt;ul&gt;
              &lt;li&gt;Verify the authentication setting for the resource and then try requesting the resource using that authentication method.&lt;/li&gt;
              &lt;li&gt;Verify that the client browser supports Integrated authentication.&lt;/li&gt;
              &lt;li&gt;Verify that the request is not going through a proxy when Integrated authentication is used.&lt;/li&gt;
              &lt;li&gt;Verify that the user is not explicitly denied access in the "configuration/system.webServer/authorization" configuration section.&lt;/li&gt;
              &lt;li&gt;Check the failed request tracing logs for additional information about this error. For more information, click 
                  &lt;a href="http://go.microsoft.com/fwlink/?LinkID=66439"&gt;here&lt;/a&gt;.
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/fieldset&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Do I need to configure my Postman request with some type of special header in order for this to work?</p>