You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Function应用服务计划中ServicePointManager.DefaultConnectionLimit设置位置

Setting ServicePointManager.DefaultConnectionLimit in Azure Functions (App Service Plan)

Great question! When running Azure Functions on an App Service Plan (non-consumption), you need to set this static property early in your application's lifecycle—before any outbound HTTP connections are made. Here's where and how to do it:

Primary Placement: Application Startup Code

The best spot is in your function app's initialization logic, which runs once when the app starts up (not per function execution). This ensures the setting applies globally to all functions in the app.

For .NET 6+ (Isolated Worker Model or In-Process)

If you're using the modern .NET stack, add the setting in your Program.cs when configuring the host:

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(services =>
    {
        // Adjust the value based on your outbound connection needs
        System.Net.ServicePointManager.DefaultConnectionLimit = 100;
    })
    .Build();

host.Run();

For .NET Framework (Legacy In-Process)

If you're on .NET Framework, place the setting in Global.asax.cs's Application_Start method:

protected void Application_Start()
{
    System.Net.ServicePointManager.DefaultConnectionLimit = 100;
    // Other app initialization code here
}

Why Not Set It in Individual Functions?

Avoid setting this property inside a specific function's execution logic. Since ServicePointManager is static, changes made mid-execution might not apply to already-established connections, and could lead to inconsistent behavior across function invocations. Setting it at startup guarantees the value is applied before any outbound HTTP calls are initiated.

Key Note

Remember, this setting controls the maximum number of concurrent connections to a single HTTP server. Adjust the value based on your app's outbound traffic patterns—don't just set it to an arbitrarily high number without testing, as it could lead to resource contention.

内容的提问来源于stack exchange,提问作者JeffC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:52:23