Context: ASP.NET Web API v2

Given an URL similar to this one:

http://localhost/something?id=cbc66d32-ece8-400f-a574-e36b911e1369

When the web method defines an "id" querystring parameter like this:

[FromUri] Guid? id = null

Then the web method gets called, whether the Guid is an invalid thing such as "asdf" or is completely ommited, the id variable gets filled with null.


We need to throw a HTTP 400 to the client on an invalid Guid, but do some valid generic processing on a null one. Those are very different outcomes. We thus need to differentiate them but get the same input on the method call.

Is there an efficient way to configure ASP.NET Web API so that it issues a HTTP 400 on invalid Guids all over the board? We use nullable Guids quite often and are expecting this kind of behaviour every time.

Related posts

Recent Viewed