ASP.NET Web API : Correct way to return a 401/unauthorised response

后端 未结 8 1236
后悔当初
后悔当初 2020-11-28 08:41

I have an MVC webapi site that uses OAuth/token authentication to authenticate requests. All the relevant controllers have the right attributes, and authentication is workin

8条回答
  •  余生分开走
    2020-11-28 09:45

    You also follow this code:

    var response = new HttpResponseMessage(HttpStatusCode.NotFound)
    {
          Content = new StringContent("Users doesn't exist", System.Text.Encoding.UTF8, "text/plain"),
          StatusCode = HttpStatusCode.NotFound
     }
     throw new HttpResponseException(response);
    

提交回复
热议问题