title: How to return 403 Forbidden response as IActionResult in ASP.NET Core
body: <p>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?</p>
  
  <p>I searched over the internet but I found only these for MVC 5:</p>
  
  <blockquote>
    <p>If the return type for your web api method is HttpResponseMessage then
    you need to use the below code:</p>
  
  <pre><code>return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "RFID is disabled for this site.");
  Or  if the return type for your web api method is IHttpActionResult then you need to use the below code
  
  return StatusCode(HttpStatusCode.Forbidden,"RFID is disabled for this site.");
  </code></pre>
    
    <p>How to return 403 for IActionResult type: </p>
  
  <pre><code>public IActionResult Put(string userid, [FromBody]Setting setting)
   {
      var result = _SettingsRepository.Update(userid, setting);
      if (result == true)
      {
         return Ok(201);
      }
      else
      {
         return BadRequest();
      }
   }
  </code></pre>
  </blockquote>