Search code examples
c#asp.net-coreazure-service-fabrickestrel-http-server

Setting MaxURLLength of HTTPGet Call in asp.net core


Hi I need to update the maxurllength of asp.net core service that is running on a service fabric cluster using kestral server. Looking at other solutions people have recomended making changes to registry and web.config but in case of Kestral server running asp.net core on service fabric we dont have any web.config file. Kestral server limits does not expose a way of doing this either. Is it possible to do so in ASP.net core?

Update:

I was using service fabric reverse proxy to access the service and a sample problematic URL is :

http://localhost:19081/{appname}/{servicename}/test-backend/v1.0/mode/1/context/5e2550ec-539a-4ea0-81b5-f783ce3f7c48/file/60917927-8a7d-4702-93e4-e2a5ea337937/version/2d826211703581a186b3d5d840e78117903189a5/openfile/W3sia2V5IjoiNjA5MTc5MjctOGE3ZC00NzAyLTkzZTQtZTJhNWVhMzM3OTM3OjJkODI2MjExNzAzNTgxYTE4NmIzZDVkODQwZTc4MTE3OTAzMTg5YTU6MCIsImNvbnRleHRJZCI6IjVlMjU1MGVjLTUzOWEtNGVhMC04MWI1LWY3ODNjZTNmN2M0OCIsImlNb2RlbElkIjoiNjA5MTc5MjctOGE3ZC00NzAyLTkzZTQtZTJhNWVhMzM3OTM3IiwiY2hhbmdlU2V0SWQiOiIyZDgyNjIxMTcwMzU4MWExODZiM2Q1ZDg0MGU3ODExNzkwMzE4OWE1Iiwib3Blbk1vZGUiOjEsIl9fbmFtZV9fIjoiSU1vZGVsVGlsZVJwY0ludGVyZmFjZV9JTW9kZWxUb2tlbiIsIl9fdW5yZWdpc3RlcmVkX18iOmZhbHNlfSwiMHgyWdpc3RlcmVkX18iOmZhbHNlfSwiMHgy

The last URL segment which is some encoded string is the issue.


Solution

  • For ASP.NET Core 1.1 KestrelServerLimits.MaxRequestLineSize should be what you are looking for.

    For ASP.NET Core 2.1 KestrelServerLimits.MaxRequestLineSize should be what you are looking for.

    The default on both is 8Kb, so that should be much bigger than the default 2083 Url length provided by chrome and other browsers.

    If you are exposing your APIs using the Service Fabric Reverse Proxy, the problem should be the Reverse Proxy and not Kestrel.

    Service Fabric Reverse Proxy uses the windows HTTP.sys driver to expose the http endpoints, by default this is limited to 260 chars per segment (values between each slash '/'), if this is the case, you should configure your machine with other values instead, in this case, you should set the value for UrlSegmentMaxLength

    To do that you have to create a DWORD called UrlSegmentMaxLength under the following registry key: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters and set it to a number between 0 and 32,766.

    I think if you provide the real problem, we could help with a better solution.