Returning 403 from custom binder

We are using some custom model bindings for our .Net Core api and have some logic in the glue module that should sometimes cause 403

our api to return .

I am aware that you can use Mvc.ModelBinding.ModelBindingResult.Failed()

to return 400

on unsuccessful model binding, however, if it was due to a failure as a result of an attempt to access Unauthorized

, we need to return 403

, ideally with a custom message.

+3


source to share


2 answers


Can't you return a status code ?. You can attach your own message.



return StatusCode(403);

      

0


source


We ultimately decided to go with a ModelBindingResult.Failed()

and a custom error message that indicated that the failure was due to an authorization failure.



0


source







All Articles