我试图弄清楚如何为用户生成基于时间的令牌,以访问存储在Azure存储帐户Blob容器中的数据。用户上载了各种数据(PDF,图像),但我不想公开此数据的链接。推荐的策略是使用SAS令牌,我可以使用大约一年前在MS网站上发现的以下功能使它在.Net下工作:
//Function for getting a temporary Azure SAS
public static string GetazureSASToken(string userhashid,int minutes)
{
//Get Azure SAS Token so we can allow them to temporarily view the photos
UploadedFileInfo uploadedfileinfo = new UploadedFileInfo();
//Azure User containter must be all lowercase!!
uploadedfileinfo.usercontainer = "user-" + userhashid;
uploadedfileinfo.azureurl = Configurationmanager.AppSettings["AzureURL"].ToString() + uploadedfileinfo.usercontainer + "/";
// Retrieve storage account from connection string.
string azureconnection = CloudConfigurationmanager.GetSetting("StorageConnectionString");
CloudStorageaccount storageaccount = CloudStorageaccount.Parse(azureconnection);
CloudBlobClient client = storageaccount.CreatecloudBlobClient();
CloudBlobContainer blobContainer = client.getcontainerReference(uploadedfileinfo.usercontainer);
//Set the expiry time and permissions for the container.
//In this case no start time is specified,so the shared access signature becomes valid immediately.
SharedaccessBlobPolicy sasConstraints = new SharedaccessBlobPolicy();
sasConstraints.SharedaccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(minutes);
sasConstraints.Permissions = SharedaccessBlobPermissions.Read;
//Generate the shared access signature on the container,setting the constraints directly on the signature.
string sasContainerToken = blobContainer.GetSharedaccessSignature(sasConstraints);
return sasContainerToken;
}
问题是我现在需要从 Asp.Net Core 2.2 应用访问这些文件,而且我似乎无法弄清楚如何复制代码以获取令牌(Core库不同)
关于如何在.Net Core 2.2中实现此目标的任何建议?
谢谢!