4

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|

2

1 Answer 1

6

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

enter image description here

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.