【发布时间】:2017-07-14 06:10:52
【问题描述】:
我想在尝试执行无效操作时向客户端返回 403 Forbidden。我需要使用什么方法?
我在互联网上搜索,但只找到 MVC 5 的这些:
如果您的 web api 方法的返回类型是 HttpResponseMessage 那么 您需要使用以下代码:
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.");IActionResult 类型如何返回 403:
public IActionResult Put(string userid, [FromBody]Setting setting) { var result = _SettingsRepository.Update(userid, setting); if (result == true) { return Ok(201); } else { return BadRequest(); } }
【问题讨论】:
标签: c# asp.net-core