值不能为null。 (参数; sharedKeykeyCredential;)
我们正在从V11迁移代码以使用Azure Storage V12客户端库(Azure.storage.blobs 12.12.0)。当我们尝试使用GeneratesAsuri()方法创建SAS URI时,请获取以下提到的例外。
异常:“值不能为null。(参数'sharedKeyCredential')””
this.blobContainerClient = new BlobContainerClient(
new Uri($https://{storageAccountName}.blob.core.windows.net/{containerName}),
new ManagedIdentityCredential(managedIdentityAppId));
var blobClient = blobContainerClient.GetBlobClient(blobName);
BlobSasBuilder sasBuilder = new()
{
BlobContainerName = containerName,
BlobName = blobName,
Resource = "b",
StartsOn = DateTime.UtcNow.AddMinutes(-15),
ExpiresOn = expirationTimeUtc
};
sasBuilder.SetPermissions(requestedPermission);
return blobClient.GenerateSasUri(sasBuilder);
We are migrating the code to use azure storage v12 client libraries (Azure.Storage.Blobs 12.12.0) from V11. Getting the below mentioned exception when we try to create SAS Uri using GenerateSasUri() method.
Exception: "Value cannot be null. (Parameter 'sharedKeyCredential')"
this.blobContainerClient = new BlobContainerClient(
new Uri($https://{storageAccountName}.blob.core.windows.net/{containerName}),
new ManagedIdentityCredential(managedIdentityAppId));
var blobClient = blobContainerClient.GetBlobClient(blobName);
BlobSasBuilder sasBuilder = new()
{
BlobContainerName = containerName,
BlobName = blobName,
Resource = "b",
StartsOn = DateTime.UtcNow.AddMinutes(-15),
ExpiresOn = expirationTimeUtc
};
sasBuilder.SetPermissions(requestedPermission);
return blobClient.GenerateSasUri(sasBuilder);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用所谓的用户代表团键为广告验证(包含托管服务身份)用户创建SAS URI。
从这里阅读更多:
创建一个用户代表团SAS对于带有.NET的容器,目录或BLOB
示例代码(从上面的链接缩写):
请注意,用户代表键不能像共享键一样长。我认为UDK的最高持续时间是几天或几周的规模,而您可以使用几个月的SAS URL,并带有共享键。
You CAN create SAS Uris for AD authenticated (incl managed service identities) users as well, with what is called user delegation key.
Read more from here:
Create a user delegation SAS for a container, directory, or blob with .NET
Example code (abbreviated from the link above):
Note that user delegation keys cannot be as long-lived as shared keys. I think the max duration for UDK was in the scale of days or a few weeks, while you could use months for SAS urls with shared keys.
托马斯指出了这一问题的原因。代码中最好处理的最好是检查您的
blobclinet
是否能够使用cangenerate> cangeneratesasulate
Thomas pointed out the cause for this issue. The best to handle in your code is to check whether your
blobclinet
can able to create the sas usingCanGenerateSasUri