I need in MCV4 web-api to return a http status to user (after calling POST/GET methods).
(New project of MCV4, and choose: WEB-API).
I have VS 2010, and I looked at the sample on Returning http status code from Web Api controller , but it didn't work for me.
I am using ApiController to handle GET/POST methods.
For following code:
[ResponseType(typeof(User))]
public HttpResponseMessage GetUser(HttpRequestMessage request, int userId, DateTime lastModifiedAtClient)
{
var user = new DataEntities().Users.First(p => p.Id == userId);
if (user.LastModified <= lastModifiedAtClient)
{
return new HttpResponseMessage(HttpStatusCode.NotModified);
}
return request.CreateResponse(HttpStatusCode.OK, user);
}
I put the above in class of type: apicontroller - ResponseType is unknown, and indeed, in code, I added:
using System.Web.Http;
But, still ResponseType is unknown.
I am using 32bit for my win-api.
How can I return status to user (whether it is error, or OK).
Thanks :)
As per MSDN document, the ResponseTypeAttribute is in the namespace "System.Web.Http.Description"
Refer: ResponseTypeAttribute
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.