0

I'm totally new in web development and I tried to create a simple rest api in vs2019/windows server 2016 for evaluation purpose.

My case/issue is as follows. I have a simple controller which has a 2 argument(string, string) method. If the whole request utf8 string is > 2101 characters the server returns a 404 in general.

I test this limitless time, with a dummy ("AAAAA.....") request string. 2002 length fails and 2001 length works. I tried to fix web.config but without luck, now I have a maxQueryStringLength exception.

Can anyone point me to the right direction?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Is it a `Get` API ? – Chetan Jan 19 '20 at 22:04
  • would it make sense to put all your parameters in the URL, and why you are not trying to send your parameters using the body ? – sayah imad Jan 19 '20 at 22:10
  • You're running up against an extreme case here. General guideline is that URLs shouldn't be longer than ~2000 characters because unexpected things start happening. There is a pretty good explanation [here](https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers). – Bradford Dillon Jan 20 '20 at 03:55

1 Answers1

0

In your site web.config, add the following configuration (modifying existing elements when they are present, otherwise adding new elements):

<system.webserver>
  <security> 
    <requestFiltering> 
      <requestLimits maxUrl="65535" maxQueryString="65535"/> 
    </requestFiltering> 
  </security> 
</system.webServer>

and

<system.web> 
  <httpRuntime maxRequestLength="65535" maxUrlLength="65535" maxQueryStringLength="65535" />
</system.web>

do not forget to restart the site or iis after doing changes.

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26