Azure KeyVault在运行getSecret()运行时给出了null引用异常
当我尝试从Azure KeyVault获取API Secret时,我会收到一个无参考错误。我在密钥维护中设置了密钥,但是秘密以null
返回。
public static string GetKeyInformation(API_KEY)
{
if (string.IsNullOrEmpty(API_KEY))
{
var keyVaultUrl = "https://socialflutter.vault.azure.net/";
var credential = new DefaultAzureCredential();
var client = new SecretClient(vaultUri: new Uri(keyVaultUrl), credential);
KeyVaultSecret secret = client.GetSecret();
Console.WriteLine($"{secret.Name}: {secret.Value}");
API_KEY = secret.Value;
}
return API_KEY;
}
任何帮助将不胜感激。
When I try to get the API secret from Azure KeyVault, I am receiving a null reference error. I have the Key set up in the KeyVault, but secret is coming back as null
.
public static string GetKeyInformation(API_KEY)
{
if (string.IsNullOrEmpty(API_KEY))
{
var keyVaultUrl = "https://socialflutter.vault.azure.net/";
var credential = new DefaultAzureCredential();
var client = new SecretClient(vaultUri: new Uri(keyVaultUrl), credential);
KeyVaultSecret secret = client.GetSecret();
Console.WriteLine(quot;{secret.Name}: {secret.Value}");
API_KEY = secret.Value;
}
return API_KEY;
}
Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于以下行,正在发生空引用错误:
即使您只有一个秘密定义,Azure KeyVault也不知道如何读取键。
您将需要以下语法:
要查找
< key_name>
,请参阅下面的屏幕截图:The null reference error is happening because of the following line:
Even if you just have a single secret defined, Azure KeyVault will not know how to read the Key.
You will want the following syntax:
To find the
<KEY_NAME>
, refer to the screenshot below: