Here is an article about some extended HTTP codes:
IIS 7.0, IIS 7.5, and IIS 8.0 define several HTTP status codes that indicate a more specific cause of a 401 error. The following specific HTTP status codes are displayed in the client browser but are not displayed in the IIS log:
- 401.1 - Logon failed.
- 401.2 - Logon failed due to server configuration.
- 401.3 - Unauthorized due to ACL on resource.
- 401.4 - Authorization failed by filter.
- 401.5 - Authorization failed by ISAPI/CGI application.
I need some custom extended HTTP codes like these:
- 401.10 - User not found
- 401.11 - User password mismatch
- 401.12 - User account is locked
- 401.13 - User account is expired
- ...
How to return these extended 401 error codes from .NET MVC application?
401 Unauthorized is the status code to return when the client provides no credentials or invalid credentials. 403 Forbidden is the status code to return when a client has valid credentials but not enough privileges to perform an action on a resource.
The HTTP 402 Payment Required is a nonstandard response status code that is reserved for future use. This status code was created to enable digital cash or (micro) payment systems and would indicate that the requested content is not available until the client makes a payment.
The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code indicates that the client request has not been completed because it lacks valid authentication credentials for the requested resource.
In your action method you set the status codes manually:
Response.StatusCode = 401;
Response.SubStatusCode = 10;
Additionally, you can use the HttpStatusCode enumeration in System.Net:
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With