Reputation: 223
I am working on a web-api and I have set the web config file to accept 6144 as the max length of the url as below
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime maxUrlLength="6144"
relaxedUrlToFileSystemMapping="true"
targetFramework="4.5"/>
When I call the api with 299 characters everything works fine, but with more than 299 characters it serves up a Bad Request - Invalid URL
sample url:
http://localhost:56835/api/multibuys/10270001C1001034900|10358419P4001027620|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|
Upvotes: 4
Views: 4643
Reputation: 17749
I've had the same issue when self hosting web-api. I would guess the limit you are hitting is the UrlSegmentMaxLength
default from Http.sys.
To fix this you need to add a new registry DWORD under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters
called UrlSegmentMaxLength
and give this the value you desire:
UrlSegmentMaxLength 260 0 - 32,766 chars Maximum number of characters in a URL path segment (the area between the slashes in the URL). If zero, it is the length that is bounded by the maximum value of a ULONG.
To add via the command line use (elevated prompt)
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters /v UrlSegmentMaxLength /t REG_DWORD /d 32766 /f
References:
https://serverfault.com/questions/66410/iis-6-on-x64-and-long-urls
http://support.microsoft.com/kb/820129
Upvotes: 6