title: "Cannot redirect after HTTP headers have been sent." When returning HttpResponseMessage with HttpStatusCode.Unauthorized
body: <p>I'm using the new Web Api beta and wish to return </p>
  
  <p><code>HttpResponseMessage&lt;MyObject&gt;(new MyObject{ MyMessage = "Go Away!" }, HttpStatusCode.Unauthorized)</code> </p>
  
  <p>from one of my ApiController actions.</p>
  
  <p>Forms Authentication hijacks the response, crashes and adds the error <code>"Cannot redirect after HTTP headers have been sent."</code> and it's html to the response.</p>
  
  <p>Normal suppression techniques like <a href="http://haacked.com/archive/2011/10/04/prevent-forms-authentication-login-page-redirect-when-you-donrsquot-want.aspx" rel="nofollow">this</a> don't work with Web Api.</p>
  
  <p>Has anyone found a work around to this?</p>
  
  <p>I've looked at <a href="http://forums.asp.net/t/1772764.aspx/1" rel="nofollow">this forum post</a> where people report the same problem but the solutions there don't work for this case. The first solution suggested uses the normal suppression technique which doesn't work for web api. The second uses a HttpMessageHandler to intercept the request before it gets to the controller, I want the controller to fire as normal.</p>
  
  <p>After looking into the <code>DelegatingHandler</code> I can get access to the <code>HttpResponseMessage</code> but have no idea what to do with it to stop FormsAuth from redirecting.</p>