简体   繁体   English

Azure .NET v4 SDK .NET框架中的代理配置

[英]Azure .NET v4 SDK Proxy Configuration in .NET Framework

I'm using the newer v4.x version of the Azure .NET SDKS - https://www.nuget.org/packages/Azure.Security.KeyVault.Secrets/4.1.0我正在使用 Azure .NET SDKS 的较新 v4.x 版本 - https://www.nuget.org/packages/Azure.Security.KeyVault.Secrets/4.1.0

In my case this is to access Key Vault secrets but the question probably applies globally.在我的例子中,这是访问 Key Vault 机密,但这个问题可能适用于全球。 When using the above nuget package to retrieve a secret through a .NET Core 3.1 app, all seems to work OK.当使用上面的 nuget package 通过 .NET Core 3.1 应用程序检索秘密时,一切似乎都正常。

var credential = new ClientSecretCredential("<TENANT_ID>", "<CLIENT_ID>", "<SECRET>");

var client = new SecretClient(new Uri("https://MyVault.vault.azure.net/"), credential);
var secret = await client.GetSecretAsync("MySecret");

However I need it to run in a .NET Framework 4.7.1, the call eventually times out after retrying 4 times.但是我需要它在 .NET Framework 4.7.1 中运行,重试 4 次后调用最终超时。

I fully suspect this is down to the corporate proxy I work behind (although if there may be other reasons please tell me).我完全怀疑这是我背后工作的公司代理人造成的(尽管如果可能有其他原因请告诉我)。

There is a SecretClientOptions that inherits from ClientOptions which contains a Transport property but it is not immediately obvious how to use this.有一个继承自ClientOptionsSecretClientOptions ,它包含一个Transport属性,但如何使用它并不是很明显。

I see on other versions of the Node SDK they have a proxyOptions property but that doesn't exist in the .NET version.我在其他版本的节点 SDK上看到它们有一个proxyOptions属性,但在 .NET 版本中不存在。 Is there another way to configure this?还有另一种配置方法吗?

I also wanted to try an diagnose a bit further but am not sure how to use the Diagnostics property and I struggle to get Fiddler to capture any .NET traffic these days.我还想进一步尝试诊断,但不确定如何使用Diagnostics属性,这些天我很难让 Fiddler 捕获任何 .NET 流量。

UPDATE : Looks like a fix for this was committed 9 days ago so expecting a fix soon which will make .NET Framework use the system proxy correctly - https://github.com/Azure/azure-sdk-for.net/issues/16990更新:看起来这个问题的修复是在 9 天前提交的,所以期待很快修复,这将使 .NET 框架正确使用系统代理 - https://github.com/Azure/azure-sdk-for.net/issues/16990

After diving into the library code it appears that the normal proxy as used with HttpClient isn't used.在深入研究库代码后,似乎没有使用与 HttpClient 一起使用的普通代理。 By setting the HTTP_PROXY and HTTPS_PROXY environment variables I was able to get this to work.通过设置 HTTP_PROXY 和 HTTPS_PROXY 环境变量,我能够让它工作。

Environment.SetEnvironmentVariable("HTTP_PROXY", "http://my.corporate.proxy/");
Environment.SetEnvironmentVariable("HTTPS_PROXY", "http://my.corporate.proxy/");

UPDATE : Looks like a fix for this was committed 9 days ago so expecting a fix soon which will make .NET Framework use the system proxy correctly - https://github.com/Azure/azure-sdk-for.net/issues/16990更新:看起来这个问题的修复是在 9 天前提交的,所以期待很快修复,这将使 .NET 框架正确使用系统代理 - https://github.com/Azure/azure-sdk-for.net/issues/16990

An alternative solution here can be the answer by Mun here .这里的替代解决方案可以是Mun here的回答。 He suggests to cache the Key Vault values in App Settings Data structure.他建议在 App Settings Data 结构中缓存 Key Vault 值。

You can also try this approach suggested by Docs if you don't prefer above approach.如果您不喜欢上述方法,也可以尝试 Docs 建议的这种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM