Invalid HTTP response code from ASP.NET web interface

I am trying to return a 401 (unauthorized) response code from the ASP.NET Web API Web Method (POST), but I get 404. Am I something wrong?

throw new HttpResponseException(HttpStatusCode.Unauthorized); (or set it to HttpResponseMessage)

thanks

+4
source share
1 answer

Grrr - the problem was forms authentication, which captures 401 and sends a redirect (302) to the nonexistent login form, so 404. I just needed to set the authentication mode to none in the web.config file.

+2
source

Source: https://habr.com/ru/post/1411531/


All Articles