我想使用 Visual Studio (2022) 從本地計算機的 Azure 存盤帳戶中的私有容器下載 Blob。
為了實作我正在使用的
DefaultAzureCredential credential = new DefaultAzureCredential();
Uri uri = new Uri("https://xxx.blob.core.windows.net/xxx/xxx.json");
BlobClient blobClient = new BlobClient(uri, credential);
Response<BlobDownloadResult> downloadResponse = blobClient.DownloadContent();
當我執行代碼時,出現以下錯誤
發行人驗證失敗。發行人不匹配。
我在 VS 2022 中進行了身份驗證,如下所述:托管身份 - 如何在本地除錯
我需要做什么才能成功下載 Blob?
uj5u.com熱心網友回復:
如https://docs.microsoft.com/en-us/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet 中所述,DefaultAzureCredential 嘗試不同的選項來獲取憑據,其中之一是 VisualStudioCredential。
為了讓它在本地作業,我必須提供 VisualStudioTenantId:
DefaultAzureCredentialOptions defaultAzureCredentialOptions = new DefaultAzureCredentialOptions()
{
VisualStudioTenantId = "xxx"
};
DefaultAzureCredential credential = new DefaultAzureCredential(defaultAzureCredentialOptions);
Uri uri = new Uri("https://xxx.blob.core.windows.net/xxx/xxx.json");
BlobClient blobClient = new BlobClient(uri, credential);
Response<BlobDownloadResult> downloadResponse = blobClient.DownloadContent();
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/363460.html
標籤:视觉工作室 验证 下载 azure-blob-storage 当地的
