webapi odata - 长 url 导致 "HTTP Error 400. The request URL is invalid"

webapi odata - long url causes "HTTP Error 400. The request URL is invalid"

我们有一个自托管的项目 odata/webapi。当收到带有长字符串的请求时,我们会收到以下错误:

"HTTP Error 400. The request URL is invalid"

是否可以将 webapi 配置为接受更长的参数?

一个例子url:

GET
/api/bookings/Service.GetSegments(ids='189,196,280,301,316,329,491,511,464,528,530,527,542,372,283,259,231,56,84,98,114,135,175,154,161,85,203,206,217,284,343,344,357,419,425,112,586,432,441,448,455,462,465,358,371,385,392,399,405,413,581,526,538,531,476,490,336,508,525,499,315,260,263,281,224,238,245,246,99,57,58,77,168,180,147,126,133',start='2018-01-20T23:00:00.000Z',end='2018-01-27T23:00:00.000Z') 

像这样更短的 url 就可以了:

GET
/api/bookings/Service.GetSegments(ids='189,196,280,301,316,329,491',start='2018-01-20T23:00:00.000Z',end='2018-01-27T23:00:00.000Z') 

这是控制器中的方法:

 public IHttpActionResult GetSegments(ODataQueryOptions<Segments> odataQueryOption,
        string ids, string start, string end)
    {
       ...

如果将 url 段替换为查询字符串,它将正常工作。

默认情况下,url 个片段的最大长度为 260。