This project has moved and is read-only. For the latest updates, please go here.

FromURI action param being validated


Web Api 5.2.3, hosted in IIS using Owin.Host.SystemWeb

We have a Web Api (5.2.3) controller action with the following signature which we want the request body to be validated by FluentValidation, but the URI params to be bound but not validated:
public IHttpActionResult Put([FromUri] string userId, Resources.Identity[] identities)
We have written a custom validator for the "identities" param but when the code executes, an error occurs which appears to be caused by not being able to find a Validator for the "userId" param.

Looking through the history of issues, my understanding was that anything marked with the FromUri attribute would not fire any validation but this doesn't seem to be the case:
Unable to resolve type: FluentValidation.IValidator`1[[System.String, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
Due to the way the URIs have been designed, the userId must remain in the action signature. I have stepped into the Web Api source during debugging and it appears that FromUri should be validating as it uses the CompositeModelBinder class to invoke the validators - can anyone suggest anything else I should try?


JeremyS wrote Feb 25, 2015 at 10:21 AM

You'll need to ensure that your validator factory checks whether or not a validator is defined before trying to resolve it.

delimited wrote Feb 25, 2015 at 12:23 PM

Thanks, it worked - hangs head in shame :-(