2

Microsoft.AspNetCore.Http.StatusCodes contains lots of status code constants useful for returning from a controller and can for example be used like this in a controller:

return StatusCode(StatusCodes.Status201Created);

But oddly the StatusCodes class contains no value for 422 Unprocessable Entity, at least not in Asp.Net Core 1.0.1. Why doesn't it contain StatusCodes.Status422UnprocessableEntity ?

Has this http status code been depreciated by some spec I am unaware of? Or is there some other reason that 422 Unprocessable Entity wasn't included?

RonC
  • 31,330
  • 19
  • 94
  • 139

2 Answers2

4

Actually it is included in Microsoft.AspNetCore.Http.StatusCodes.

Please find current list in: StatusCodes.cs


HTTP Status Code 422 is WebDAV specific (RFC 4918) and it was added to Microsoft.AspNetCore.Http.StatusCodes a little bit later.

(See details of Added HTTP Status codes #654 pull request)


But it was a few months ago, so the question is what version of ASP.NET Core are you using?


Update:

As Ron C noticed - this status code is included in v1.1 (and not available in v1.0.1).

Lukasz Mk
  • 7,000
  • 2
  • 27
  • 41
  • 1
    Sure enough! Thank you. I'm running Asp.Net Core 1.0.1 and it doesn't exist in this version. But I see that it does exist in 1.1 on GitHub thanks to the info you provided. – RonC Jan 25 '17 at 14:21
  • Yes, I'm running v1.1 so I see const for 442, but you are right, it looks like it was included after v1.0.1 was released. – Lukasz Mk Jan 25 '17 at 14:35
1

I wouldn’t know why but I did a quick search and found this post.

As of 2015, @Tom Christie mentioned the following:

Behaviorally both 400 and 422 response codes will be treated the same by clients and intermediaries, so it actually doesn't make a concrete difference which you use.

And this:

422 Is specifically a WebDAV extension, and is not referenced in RFC 2616 or in the newer HTTPbis specification.

Maybe...just maybe...the reason why the status code 422 isn’t part of the Microsoft.AspNetCore.Http.StatusCodes might be because it is a WebDAV extension but don’t take my word for it as I’m only trying to raise awareness as to what could be the cause.

Community
  • 1
  • 1
Vlince
  • 5,885
  • 7
  • 45
  • 62