0

I have a [HttpDelete] action in my Web API, and when I invoke it with a long URL, I get 400.

I know for sure it's the URL length since I managed to fail / pass the request by adding and removing a single character.

I had a similar issue with [HttpGet] request length which I had resolved by adding configurations to my web.config:

Under system.web:

<httpRuntime maxRequestLength="1048576" maxQueryStringLength="32768" maxUrlLength="65536" waitChangeNotification="2147483647" maxWaitChangeNotification="2147483647" requestPathInvalidCharacters="" targetFramework="4.5" />

Under system.webServer:

<security>
   <requestFiltering>
      <requestLimits maxAllowedContentLength="1073741824" maxQueryString="32768" maxUrl="65536"/>
   </requestFiltering>
 </security>

But the issue seems to be reproducing in the Delete action as well, and I'm failing to come with a solution. I'm not getting anything in IIS trace and IIS logs as well.

How to fix this?

Y.S
  • 1,860
  • 3
  • 17
  • 30
  • I've got a feeling it is 2mb from some work I did in the past with requests over HTTP, depending on the browser/server software (there is no limit in the HTTP spec). How many characters are we talking about? – VictorySaber Oct 27 '15 at 11:58
  • 1
    I'm sure you'll find the question _"Why on earth do you have such long URIs?"_ annoying, but really, why? Is your _only_ option to allow longer URIs? – CodeCaster Oct 27 '15 at 11:59
  • 338 for the entire URL, the route parameter in question (string) fails with length of 261 and passes with 260 chars – Y.S Oct 27 '15 at 12:00
  • @CodeCaster I so agree with you, but it's a business requirement i unfortunately cannot change at the moment. – Y.S Oct 27 '15 at 12:01

1 Answers1

0

So I think I found the cause, looks like Microsoft limits URL segments to 260.

more information here, look for the UrlSegmentMaxLength

https://support.microsoft.com/en-us/kb/820129

Edit:

So this is defiantly the issue.

It's not just for Delete, but for any other http type of action, that has a long segment in the URL.

the solution is to update the registry key with the value you want, should you need url segments which are over 260 characters, which is the default value.

Hope this will help someone else.

Y.S
  • 1,860
  • 3
  • 17
  • 30