Is there an enum or class in .NET containing the WebDAV http status codes
I have been using the HttpStatusCode
enumeration (msdn) to return errors in web requests, but now that I want to return a 422, "Unprocessable Entity" (webdav.org), I see that it is not among the enum's members.
I am not able to find anything in the .NET framework, and I would lik开发者_StackOverflow社区e to avoid custom solutions (devio.wordpress.org) if I can help it (i.e. if something does indeed exist).
The scenario is this: The client posts a request, and validation occurs in the server. After a quick search on SO I decided that 422 is perhaps the most appropriate, or maybe a 400.
So, does anyone know if there is an enum or class in .NET 4.0 containing the WebDAV http status codes?
Thank you!
No, no such file is defined -- I had the same requirements for an API I'm building and decided to simply typecast it (which is possible with int enums) like this:
try {
if (!Repository.Cancel(IdHelper.Decrypt(id))) {
return Request.CreateResponse(HttpStatusCode.NotFound, "Booking not found");
}
}
catch (Exception x) {
// typecast 422 to enum because it's not defined in HttpStatusCode
return Request.CreateResponse((HttpStatusCode)422, x.Message);
}
精彩评论