在asp.net核心中设置HTTPGet调用的MaxURLLength

时间:2018-11-13 12:08:00

标签: c# asp.net-core azure-service-fabric kestrel-http-server

嗨,我需要更新使用kestral服务器在服务结构群集上运行的asp.net核心服务的最大长度。 在查看其他解决方案时,人们建议对注册表和web.config进行更改,但是如果Kestral服务器在服务结构上运行asp.net核心,我们将没有任何web.config文件。 Kestral server limits也没有公开执行此操作的方法。是否可以在ASP.net核心中这样做?

更新:

我正在使用服务结构反向代理访问服务,并且示例URL出现问题:

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

最后一个URL段是一些编码的字符串。

2 个答案:

答案 0 :(得分:2)

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.

答案 1 :(得分:0)

仅需注意一点: .NET Core应用程序也可以通过IIS托管。在这种情况下,反向代理与Kerstel进行对话。同样在“ dotnet发布”期间,为此情况创建了一个web.config,以使IIS与.NET Core一起使用。

因此,在这种情况下,这意味着您必须在两个地方都设置这些主机级别的更改。我发现this帖子中的.NET Core项目单元中的IIS配置存在很多问题。