本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudPageBlob.GetSharedAccessSignature方法的典型用法代码示例。如果您正苦于以下问题:C# CloudPageBlob.GetSharedAccessSignature方法的具体用法?C# CloudPageBlob.GetSharedAccessSignature怎么用?C# CloudPageBlob.GetSharedAccessSignature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudPageBlob
的用法示例。
在下文中一共展示了CloudPageBlob.GetSharedAccessSignature方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSasUriWithPermission
private string CreateSasUriWithPermission(string vhdName, int p)
{
// Set the destination
string vhdBlobName = string.Format("{0}/{1}.vhd", vhdContainerName, Utilities.GetUniqueShortName(Path.GetFileNameWithoutExtension(vhdName)));
string httpsBlobUrlRoot = string.Format("https:{0}", blobUrlRoot.Substring(blobUrlRoot.IndexOf('/')));
string vhdDestUri = httpsBlobUrlRoot + vhdBlobName;
var destinationBlob2 = new CloudPageBlob(new Uri(vhdDestUri), new StorageCredentials(storageAccountKey.StorageAccountName, storageAccountKey.Primary));
var policy2 = new SharedAccessBlobPolicy()
{
Permissions = (SharedAccessBlobPermissions)p,
SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromHours(1)
};
var destinationBlobToken2 = destinationBlob2.GetSharedAccessSignature(policy2);
vhdDestUri += destinationBlobToken2;
return vhdDestUri;
}
示例2: GetAzureVmSasUri
private string GetAzureVmSasUri(string vmImageName)
{
string mediaLinkUri = null;
Uri uri = null;
StorageManagementClient storageClient = null;
string storageAccountName = null;
StorageAccountGetKeysResponse getKeysResponse = null;
ErrorRecord er = null;
StorageCredentials credentials = null;
SharedAccessBlobPolicy accessPolicy = null;
CloudPageBlob pageBlob = null;
string sas = null;
mediaLinkUri = GetImageUri(vmImageName);
uri = new Uri(mediaLinkUri);
storageClient = new StorageManagementClient(this.Client.Credentials, this.Client.BaseUri);
storageAccountName = uri.Authority.Split('.')[0];
getKeysResponse = storageClient.StorageAccounts.GetKeys(storageAccountName);
if (getKeysResponse.StatusCode != System.Net.HttpStatusCode.OK)
{
er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
String.Format(Commands_RemoteApp.GettingStorageAccountKeyErrorFormat, getKeysResponse.StatusCode.ToString()),
String.Empty,
Client.TemplateImages,
ErrorCategory.ConnectionError
);
ThrowTerminatingError(er);
}
credentials = new StorageCredentials(storageAccountName, getKeysResponse.SecondaryKey);
accessPolicy = new SharedAccessBlobPolicy();
pageBlob = new CloudPageBlob(uri, credentials);
accessPolicy.Permissions = SharedAccessBlobPermissions.Read;
accessPolicy.SharedAccessStartTime = DateTime.Now;
accessPolicy.SharedAccessExpiryTime = DateTime.Now.AddHours(12);
sas = pageBlob.GetSharedAccessSignature(accessPolicy);
if (sas == null)
{
er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
Commands_RemoteApp.FailedToGetSasUriError,
String.Empty,
Client.TemplateImages,
ErrorCategory.ConnectionError
);
ThrowTerminatingError(er);
}
return mediaLinkUri + sas;
}
示例3: Initialize
public void Initialize()
{
vmPowershellCmdlets = new ServiceManagementCmdletTestHelper();
vmPowershellCmdlets.ImportAzurePublishSettingsFile();
defaultAzureSubscription = vmPowershellCmdlets.SetDefaultAzureSubscription(Resource.DefaultSubscriptionName);
Assert.AreEqual(Resource.DefaultSubscriptionName, defaultAzureSubscription.SubscriptionName);
storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccount);
Assert.AreEqual(defaultAzureSubscription.CurrentStorageAccount, storageAccountKey.StorageAccountName);
destination = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd"));
patchDestination = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd"));
destinationSasUri = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd"));
patchDestinationSasUri = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd"));
var destinationBlob = new CloudPageBlob(new Uri(destinationSasUri), new StorageCredentials(storageAccountKey.StorageAccountName, storageAccountKey.Primary));
var patchDestinationBlob = new CloudPageBlob(new Uri(patchDestinationSasUri), new StorageCredentials(storageAccountKey.StorageAccountName, storageAccountKey.Primary));
var policy = new SharedAccessBlobPolicy()
{
Permissions =
SharedAccessBlobPermissions.Delete |
SharedAccessBlobPermissions.Read |
SharedAccessBlobPermissions.Write |
SharedAccessBlobPermissions.List,
SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromHours(1)
};
var destinationBlobToken = destinationBlob.GetSharedAccessSignature(policy);
var patchDestinationBlobToken = patchDestinationBlob.GetSharedAccessSignature(policy);
destinationSasUri += destinationBlobToken;
patchDestinationSasUri += patchDestinationBlobToken;
blobUrlRoot = string.Format(@"http://{0}.blob.core.windows.net/", defaultAzureSubscription.CurrentStorageAccount);
perfFile = "perf.csv";
}