ASP.NET MVC how to handle unauthorized response in JSON for your API
Assuming you want to prepare some JSON API in your ASP.NET MVC with authorization.
To share the same authorization logics for our Controller Action, what we should probably do is to implement our own FilterAttributes.
It can be as simple as:
|
Note we are using property injection here for the IAuthTokenService
here, check out Inject Properties Into FilterAttributes for more information.
HTTP status codes
In order to add our HTTP status codes, we can simple add the following line:
Read on →