In short, let’s remember the following things about HTTP status codes in Web API projects:
- Always return the appropriate status code, however you define “appropriate”.
- Use the shortcut methods (e.g. Ok() , NotFound() , etc.) …
- An action that returns void will send status code 204 No Content.
- Open IIS and select site that is causing 401.
- Select Authentication property in IIS Header.
- Select Anonymous Authentication.
- Right click on it, select Edit and choose Application pool identity.
- Restart site and it should work.
For More Information Please Refer: https://stackoverflow.com/questions/11162430/401-unauthorized-on-a-directory