title: Return specific HTTP status code in action for GET request
body: <p>I'm creating REST service using ASP.NET Web API.
  How can I return 401 status code from action for GET method...</p>
  
  <p>I don't have problem with returning some status code from e.g. POST method, cause I can set the return type to HttpResponseMessage </p>
  
  <pre><code>   public HttpResponseMessage Post(Car car)
      {
          using (var context = new CarEntities())
          {
              ...
              var response = new HttpResponseMessage(HttpStatusCode.Created);
              response.Headers.Location = new Uri(Request.RequestUri, path);
              return response;
          }
      }
  </code></pre>
  
  <p>However, how can I return the status code for GET method, when the method returns different type than HttpResponseMessage:</p>
  
  <pre><code>public Car Get(int id)
  {
  
      var context = new CarEntities();
      return context.Cars.Where(p =&gt; p.id == id).FirstOrDefault();
  }
  </code></pre>
  
  <p>I would like to return e.g. 401 when authorization in this Get method failed</p>
  
  <p>Thanks</p>