title: How to enable Windows authentication for specific controller in ASP.Net Web API
body: <p>I was wandering if there is a way to enable Windows authentication only for the particular action of the particular ASP.Net Web API controller.  My Web API web service has a couple of controllers with numerous actions, but only one action of one controller needs Windows authentication.  This web services is implemented using Web API 2.1, and is hosted in IIS (v7.5 and above).  Even though, it’s an intranet web service I don’t want to enable windows authentication on controllers and actions that don’t need it.  Please let me know if there is a way to enable Windows authentication for a specific controller and action.</p>
  
  <p>My web service code is similar to the code below.  Only endpoint <strong><em>api/controller1/action1</em></strong> implemented by <strong><em>Controller1.Action1</em></strong> requires windows authentication.  The rest of actions don't need Windows authentication:</p>
  
  <pre><code>[RoutePrefix("api/controller1")]
  public class Controller1: ApiController
  {
      [Route("action1")]
      public HttpResponseMessage Action1()
      {
          return Request.CreateResponse&lt;object&gt;(HttpStatusCode.OK, null);
      }
      [Route("action2")]
      public HttpResponseMessage Action2()
      {
          return Request.CreateResponse&lt;object&gt;(HttpStatusCode.OK, null);
      }
  }
  
  
  [RoutePrefix("api/controller2")]
  public class Controller2 : ApiController
  {
      [Route("action1")]
      public HttpResponseMessage Action1()
      {
          return Request.CreateResponse&lt;object&gt;(HttpStatusCode.OK, null);
      }
      [Route("action2")]
      public HttpResponseMessage Action2()
      {
          return Request.CreateResponse&lt;object&gt;(HttpStatusCode.OK, null);
      }
  }
  </code></pre>
  
  <p>Thank you,
  Rita</p>