I would like to return a 403 Forbidden to the client when trying to perform an invalid operation. What is the method I need to use?
I searched over the internet but
When you want to respond with a HTTP 403 status and allow ASP.NET Core's authentication logic to handle the response with its forbidden handling logic (can be configured in your Startup class, and may cause a redirect to another page), use:
return Forbid();
(same applies to Unauthorized())
When you want to respond with a HTTP 403 status code from an API and do not want the ASP.NET Core authentication logic to perform any redirect or other action, use:
return StatusCode(403);