Returning http status code from Web Api controller

前端 未结 13 1459
一生所求
一生所求 2020-11-27 10:01

I\'m trying to return a status code of 304 not modified for a GET method in a web api controller.

The only way I succeeded was something like this:

p         


        
相关标签:
13条回答
  • 2020-11-27 10:52

    You can also do the following if you want to preserve the action signature as returning User:

    public User GetUser(int userId, DateTime lastModifiedAtClient) 
    

    If you want to return something other than 200 then you throw an HttpResponseException in your action and pass in the HttpResponseMessage you want to send to the client.

    0 讨论(0)
提交回复
热议问题