【发布时间】:2014-11-05 06:23:32
【问题描述】:
问题
我正在使用下面的代码为 Azure 存储帐户生成一个 SAS URI,这是一种享受。
但是在执行代码时,生成的控制台应用程序窗口会显示相关的 URI 字符串,但我无法复制该值。
问题
希望简单的问题,必须在下面的代码中添加什么才能将 URI 输出到文本文件?
{
使用 System.IO;
使用 Microsoft.WindowsAzure;
使用 Microsoft.WindowsAzure.Storage;
使用 Microsoft.WindowsAzure.Storage.Blob;
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text; 使用 System.Threading.Tasks;
命名空间 SAS
{ 课堂节目 { 静态无效主要(字符串 [] 参数) {
//Parse the connection string and return a reference to the storage account. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); //Create the blob client object. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); //Get a reference to a container to use for the sample code, and create it if it does > not exist. CloudBlobContainer container = blobClient.GetContainerReference("sascontainer"); container.CreateIfNotExists(); //Insert calls to the methods created below here... //Generate a SAS URI for the container, without a stored access policy. Console.WriteLine("Container SAS URI: " + GetContainerSasUri(container)); Console.WriteLine(); //Require user input before closing the console window. Console.ReadLine(); } static string GetContainerSasUri(CloudBlobContainer container) { //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 = DateTime.UtcNow.AddHours(4); sasConstraints.Permissions = SharedAccessBlobPermissions.Write | > SharedAccessBlobPermissions.List; //Generate the shared access signature on the container, setting the > constraints directly on the signature. string sasContainerToken = > container.GetSharedAccessSignature(sasConstraints); //Return the URI string for the container, including the SAS token. return container.Uri + sasContainerToken; } }} }
【问题讨论】:
标签: visual-studio-2012 azure console azure-storage