c# - .NET Azure.Identity SDK 网络超时

标签 c# .net azure

在 .NET 7 应用程序中,我尝试使用 Azure Identity。但是,我经常收到操作被取消,因为它超出了配置的超时时间 0:00:01。网络超时可以在ClientOptions.Retry.NetworkTimeout中调整。

我正在尝试增加超时时间,但它不起作用。如何适当增加超时时间

builder.Services.AddAzureClients(clientBuilder =>
{
    clientBuilder.ConfigureDefaults(options =>
    {
        options.Retry.NetworkTimeout = TimeSpan.FromSeconds(10);
    });
    
    // Add a Storage account client
    clientBuilder.AddBlobServiceClient(builder.Configuration.GetSection("AzureBlobStorage"));

    // Use DefaultAzureCredential by default
    clientBuilder.UseCredential(new DefaultAzureCredential(new DefaultAzureCredentialOptions()
    {
        Retry = { NetworkTimeout = TimeSpan.FromSeconds(10) }
    }));
});

最佳答案

该错误是由于该过程花费的时间比平时更长。

通过在代码中设置RetryOptions对象的NetworkTimeout属性增加超时时间。

You are setting the NetworkTimeout property of the RetryOptions object in two places.

  • clientBuilder 对象的 ConfigureDefaults 方法中,以及在传递给 UseCredentialDefaultAzureCredentialOptions 对象中> clientBuilder 对象的方法。

您必须在一处设置 NetworkTimeout 属性。

仅通过在 DefaultAzureCredentialOptions 对象中进行设置即可满足请求。

以下是要安装的 NuGet。

enter image description here

代码

builder.Services.AddAzureClients(clientBuilder =>
{
    clientBuilder.ConfigureDefaults(options =>
    {
    });
    clientBuilder.AddBlobServiceClient(builder.Configuration.GetSection("AzureBlobStorage"));
    clientBuilder.UseCredential(new DefaultAzureCredential(new DefaultAzureCredentialOptions()
    {
        Retry = { NetworkTimeout = TimeSpan.FromSeconds(10) }
    }));
});

enter image description here

You can also add the requestTimeout="00:20:00 in the configuration file in your slots sites/wwwroot folder.

enter image description here

欲了解更多信息,请参阅MSDocGithub Issues .

关于c# - .NET Azure.Identity SDK 网络超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76178235/

相关文章:

azure - 如何使用 Azure Synapse 删除 Databricks 上的表或行?

Azure:是否有必要为文件、blob、表、Cosmos 和 SQL 等每种资源类型提供专用的私有(private) DNS?

c# - 无法让模板缓冲区在 OpenTK 中工作,简单的 2D 四边形

c# - 如何将 byte[] 响应转换为有效的 XDocument?

c# - LINQ to SQL (CE) 速度与 SqlCe

c# - EF7(核心)中同一个表的多个关系

c# - Protobuf-net 在序列化期间跳过数据

c# - 如何检索向 C# Web 服务发出请求的客户端的 IP

c# - 带有叠加项目控件的图像

azure - 如何启用 Azure 防火墙策略的 TLS 检查和 IDPS 高级功能