生成SAS令牌后,公共访问级别发生更改 [英] Public access level changes after generating SAS token

查看:133
本文介绍了生成SAS令牌后,公共访问级别发生更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在以编程方式为Blob存储创建SAS令牌.最初,我将公共访问级别"设置为私人"(没有匿名访问).但是,当我运行代码以生成SAS令牌时,公共访问级别更改为Blob(对Blob的匿名读取访问) 只要).我看到当我从Azure门户生成SAS令牌时,访问保持不变,即私有.如何以编程方式实现这一目标?

I am creating a SAS token for Blob storage programmatically. Initially I had set Public Access Level to Private (No anonymous access). But when I run my code to generate SAS token, the Public Access Level changes to Blob (anonymous read access for blobs only). I see that when I generate the SAS token from Azure portal, then the access remains the same i.e. Private. How to achieve this programmatically?

我基本上是在尝试生成一个有效期为1小时的令牌,并将其添加到Blob URL中并将其提供给客户端以查看图像. 1小时后,客户端应无法使用旧版SAS令牌访问映像.要访问图像,客户端 应该为SAS令牌创建新请求.

I am basically trying to generate a token that will be valid for say 1 hour and add that to Blob URL and provide it to clients to see the image. After 1 hour the client should not be able to access the image with older SAS token. To access the image, client should create new request for SAS token.

请让我知道我是否缺少任何东西.

Please let me know if I am missing something.

下面是我的代码:

字符串GetBlobSasUri(CloudBlobContainer容器,字符串fileName)
{
           //获取对容器内Blob的引用.
           CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

           SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
           sasConstraints.SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5);
           sasConstraints.SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(SASTimeout);
           sasConstraints.Permissions = SharedAccessBlobPermissions.Read;

           //在Blob上生成共享访问签名,直接在签名上设置约束.
          字符串sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);

          返回sasBlobToken;
}

string GetBlobSasUri(CloudBlobContainer container, string fileName)
{
            //Get a reference to a blob within the container.
            CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

            SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
            sasConstraints.SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5);
            sasConstraints.SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(SASTimeout);
            sasConstraints.Permissions = SharedAccessBlobPermissions.Read;

            //Generate the shared access signature on the blob, setting the constraints directly on the signature.
            string sasBlobToken = blob.GetSharedAccessSignature(sasConstraints);

            return sasBlobToken;
}

推荐答案

您使用哪种类型的SAS正在尝试创建?它是基于服务的吗?你是在指这个吗 文档 用于创建SAS?

Which type of SAS you are trying to create? Is it service based? Are you referring this document for SAS creation?


这篇关于生成SAS令牌后,公共访问级别发生更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆