I have this controller action:
[ActionName("GetMany")] [HttpGet]
public IHttpActionResult GetMany([FromUri] IEnumerable<int> ids)
{
//Do something...
}
I'm also using a custom model binder as described in this SO question. My question is different from this linked question because, even though I followed the answers suggested there, it is still not working when using a custom ModelBinder
as it's throwing an exception mentioned below.
I've got this routing configured:
config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "Api/{controller}/{action}",
defaults: new { action = "Get" },
constraints: null
);
And on the client side, I do:
public IEnumerable<MyEntity> LoadMany(IEnumerable<int> ids)
{
var url = "Api/MyEntity/GetMany?ids={0}";
var s = HttpUtility.UrlEncode(string.Format(url, string.Join(",", ids)));
response = client.GetAsync(HttpUtility.UrlEncode(s)).Result;
return null; //for now
}
However, response is throwing a Not Found exception.
What am I missing here?
EDIT
I removed the registering of the custom model binder, and I changed the action to:
[ActionName("GetMany")] [HttpGet]
public IHttpActionResult GetMany([ModelBinder(typeof(ArrayModelBinder))] IEnumerable<int> ids)
{
//Do something...
}
And now I get the following exception:
HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (?)
So if ?
is not allowed in the Url, and without removing validation, how is it possible to pass the array to the action? Would changing the Get
to a Post
make sense (in order to use request.body)?