Web API 2 OData Actions Empty Post

Topics: ASP.NET Web API
Nov 23, 2013 at 4:36 PM
Edited Nov 23, 2013 at 4:37 PM
I am wanting to create an action that has a single optional "RequestedIdentity" parameter.

The reason for this is that the request is authenticated with a bearer token (using the new Web API 2 bearer host authentication features), so the bearer token is used to establish an asserted identity, with the optional "RequestedIdentity". The requested identity is useful for a user that has rights to impersonate another user (e.g. admin user) to perform an action on behalf of another user.

When I post an empty body, the ODataActionParameters collection is null rather than empty, so the ModelState.Valid call fails. If I post a body with an empty RequestedIdentity parameter - e.g.:

{ "RequestedIdentity":"" }

Then everything is OK - I get an action parameters collection with a key/value pair for the requested identity (with an empty value).

I'm guessing this is expected behaviour as I'm guessing the OData specification requires a body for any POST operation, but just wanted to check if this is the case.

It's not a major to include an empty property as per above, but as always looking for the most optimal solutions.
Nov 24, 2013 at 6:14 PM
Sorry this was a unit testing issue relating to environment setup.

You can submit empty POSTs with no problem.
Marked as answer by mixja on 11/24/2013 at 10:14 AM