status code: 400; The query specified in the URI is not valid.

Nov 10, 2012 at 1:29 AM

When I download and run
Mvc4 Client- Filtering -Paging -Sorting-updating
This dialog pops up on start and on clicking just about anything
status code: 400; The query specified in the URI is not valid.

Coordinator
Nov 10, 2012 at 9:03 AM

Try changing the order of the two action filters on the WebApi action methods that return an IQueryable:

From

[Queryable, DateConversionFilter(DateConversionFilterOperation.DeclareLocale)]

To

[ DateConversionFilter(DateConversionFilterOperation.DeclareLocale), Queryable]

There is a Bug in WebApi for which the order of execution of attributes cannot be controlled in a deterministic way, so if you modify somehow the code or update to a newer version of a nuget package the order of execution of action filters changes. So in order to fix you have to reorder the them in the code....very annoying. See here: http://www.strathweb.com/2012/06/control-the-execution-order-of-your-filters-in-asp-net-web-api/ for  more infos on this problem. 

If Microsoft doesnt fix this problem in the next release of the Mvc Controls Toolkit I will provide a solution similar to the one described in that link.

Nov 11, 2012 at 4:04 AM

Correct!
Change this
[Queryable, DateConversionFilter(DateConversionFilterOperation.DeclareLocale)]
public IQueryable<ToDoView> Get()
{
to this
[DateConversionFilter(DateConversionFilterOperation.DeclareLocale), Queryable]
public IQueryable<ToDoView> Get()
{
and we are up and running.
Thanks, Frank.

Coordinator
Nov 11, 2012 at 11:06 PM

yes but pay attention...if you modify the code the same error may appears again! Since the execution order of attributes is not reliable...so maybe you wpuld need to chenge their order again. Since at moment Microsoft has not released a fix for this problem....Probably in the next release of the Mvc Controls Toolkit I would put a patch to allow user to define execution order.

Coordinator
Nov 16, 2012 at 1:54 PM

I posted a request to Microsoft do allow the user to control deterministically the execution order of WebApi Filter. Now it is under evaluation for user feedback. Please vote it here: http://aspnet.uservoice.com/forums/147201-asp-net-web-api/suggestions/3346720-execution-order-of-mvc4-webapi-action-filters