销售电话: 1-800-867-1380

CloudBlobContainer.SetPermissions 方法 (BlobContainerPermissions)

Sets permissions for the container.

命名空间: Microsoft.WindowsAzure.StorageClient
程序集: Microsoft.WindowsAzure.StorageClient(在 microsoft.windowsazure.storageclient.dll 中)

用法
Dim instance As CloudBlobContainer
Dim permissions As BlobContainerPermissions

instance.SetPermissions(permissions)

声明
Public Sub SetPermissions ( _
	permissions As BlobContainerPermissions _
)
public void SetPermissions (
	BlobContainerPermissions permissions
)
public function SetPermissions (
	permissions : BlobContainerPermissions
)

参数

permissions

The permissions to apply to the container.

The following code example sets both public access permissions and a container-level access policy on the container. The example then generates a shared access signature for the container.

static void CreateSAS()
{
    //Retrieve storage account information from an app.config file.
    //This is one way to store and retrieve a connection string if you are writing an application 
    //that will run locally, rather than in Windows Azure.
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageAccountConnectionString"]);

    //Create the blob client object.
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

    //Get a reference to the container for which the shared access signature will be created.
    CloudBlobContainer container = blobClient.GetContainerReference("mysascontainer");
    container.CreateIfNotExist();

    //Create a permission policy to set the public access setting for the container. 
    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

    //The public access setting explicitly specifies that the container is private, so that it can't be accessed anonymously.
    containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;

    //Set the permission policy on the container.
    container.SetPermissions(containerPermissions);

    // Get the shared access signature to share with users, specifying a signature-level access policy.
    string sas = container.GetSharedAccessSignature(new SharedAccessPolicy()
    {
        SharedAccessStartTime = DateTime.Now,
        SharedAccessExpiryTime = DateTime.Now.AddHours(10),
        Permissions = SharedAccessPermissions.Write | SharedAccessPermissions.Read
    });

    //The shared access signature then can be used to create a service client. 
    //This code would likely be run from a different client, but is included here to 
    //demonstrate how to consume the shared access signature.

    //Create the blob client directly, using the shared access signature
    CloudBlobClient sasBlobClient = new CloudBlobClient(storageAccount.BlobEndpoint,
        new StorageCredentialsSharedAccessSignature(sas));

    //Return a reference to a blob.
    CloudBlob blob = sasBlobClient.GetBlobReference("mysascontainer/myblob.txt");

    //Upload text to the blob. If the blob does not yet exist, it will be created. If the blob does exist, its existing
    //content will be overwritten.
    blob.UploadText("Write to a blob using shared access credentials.");
}


The SetPermissions method sets two types of permissions for the container:

  • Public access permissions, which determine whether container data and blob resources are available for anonymous access.

  • Container-level access policies, which can be used to specify parameters for a shared access signature for the container.


此类型的任何公共静态(在 Visual Basic 中为 Shared)成员都是线程安全的。但不保证所有实例成员都是线程安全的。

开发平台

Windows XP Home Edition, Windows XP Professional, Windows Server 2003、Windows Server 2008 和 Windows 2000

目标平台

本文是否对您有所帮助?
(1500 个剩余字符)
感谢您的反馈

社区附加资源

Microsoft 正在进行一项网上调查,以了解您对 MSDN 网站的意见。 如果您选择参加,我们将会在您离开 MSDN 网站时向您显示该网上调查。

是否要参加?
显示:
© 2014 Microsoft