代码之家  ›  专栏  ›  技术社区  ›  Shahin Dohan

当不支持HTTP方法时,Web API 2不会说unauthorized

  •  -1
  • Shahin Dohan  · 技术社区  · 6 年前

    "message": "The requested resource does not support http method 'GET'."
    

    但是当我发送一个POST请求时,我得到了这样的回复:

    "message": "Authorization has been denied for this request."
    

    我不应该得到未经授权的消息,无论我做什么,如果我没有授权,甚至没有认证?

    方法如下:

    [Route("api/search"), HttpPost, Authorize]
    public async Task<IHttpActionResult> Search()
    {
       ...
    }
    

    [Authorize] 属性,我还有一个全局过滤器集。

    1 回复  |  直到 6 年前
        1
  •  1
  •   gilliduck    6 年前

    你收到的信息 GET The requested resource does not support http method 'GET' .

    由于API必须首先尝试找到与您的请求签名匹配的方法,因此您对获取not authorized的担心不起作用。因为它找不到 然后返回错误。