I’m trying to return a 401 (unauthorized) response code from ASP.NET Web API web method (POST) but I get a 404. Am I doing something wrong?
throw new HttpResponseException(HttpStatusCode.Unauthorized); (or setting it on the HttpResponseMessage)
Thanks
Grrr – the problem was forms authentication, which hijacks the 401 and issues a redirect (302) to a non-existant login form, hence the 404. I just had to set the authentication mode to none in the web.config file.