當前位置: 首頁>>代碼示例>>C#>>正文


C# CloudTable.SetPermissionsAsync方法代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.Storage.Table.CloudTable.SetPermissionsAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudTable.SetPermissionsAsync方法的具體用法?C# CloudTable.SetPermissionsAsync怎麽用?C# CloudTable.SetPermissionsAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.WindowsAzure.Storage.Table.CloudTable的用法示例。


在下文中一共展示了CloudTable.SetPermissionsAsync方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TableAclSample

        /// <summary>
        /// Manage stored access policies specified on the table
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private static async Task TableAclSample(CloudTable table)
        {
            // Set table permissions
            SharedAccessTablePolicy accessTablePolicy = new SharedAccessTablePolicy();
            accessTablePolicy.SharedAccessStartTime = new DateTimeOffset(DateTime.Now);
            accessTablePolicy.SharedAccessExpiryTime = new DateTimeOffset(DateTime.Now.AddMinutes(10));
            accessTablePolicy.Permissions = SharedAccessTablePermissions.Update;
            TablePermissions permissions = new TablePermissions();
            permissions.SharedAccessPolicies.Add("key1", accessTablePolicy);
            Console.WriteLine("Set table permissions");
            await table.SetPermissionsAsync(permissions);

            // Get table permissions
            Console.WriteLine("Get table permissions:");
            permissions = await table.GetPermissionsAsync();
            foreach (var keyValue in permissions.SharedAccessPolicies)
            {
                Console.WriteLine("  {0}:", keyValue.Key);
                Console.WriteLine("    permissions: {0}:", keyValue.Value.Permissions);
                Console.WriteLine("    start time: {0}:", keyValue.Value.SharedAccessStartTime);
                Console.WriteLine("    expiry time: {0}:", keyValue.Value.SharedAccessExpiryTime);
            }
        }
開發者ID:Azure-Samples,項目名稱:storage-table-dotnet-getting-started,代碼行數:28,代碼來源:AdvancedSamples.cs

示例2: SetTablePermissionsAsync

 /// <summary>
 /// Return a task that asynchronously set table permissions
 /// </summary>
 /// <param name="table">target table</param>
 /// <param name="tablePermissions">permissions to set</param>
 /// <param name="requestOptions">request options</param>
 /// <param name="operationContext">context</param>
 /// <returns></returns>
 public Task SetTablePermissionsAsync(CloudTable table, TablePermissions tablePermissions, TableRequestOptions requestOptions, OperationContext operationContext)
 {
     return table.SetPermissionsAsync(tablePermissions, requestOptions, operationContext);
 }
開發者ID:docschmidt,項目名稱:azure-powershell,代碼行數:12,代碼來源:StorageTableManagement.cs

示例3: CreateSharedAccessPolicy

        /// <summary>
        /// Creates a shared access policy on the table.
        /// </summary>
        /// <param name="table">A CloudTable object.</param>
        /// <param name="policyName">The name of the stored access policy.</param>
        /// <returns>A Task object</returns>
        private static async Task CreateSharedAccessPolicy(CloudTable table, string policyName)
        {
            // Create a new shared access policy and define its constraints.
            // The access policy provides add, update, and query permissions.
            SharedAccessTablePolicy sharedPolicy = new SharedAccessTablePolicy()
            {
                // Permissions enable users to add, update, query, and delete entities in the table.
                SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
                Permissions = SharedAccessTablePermissions.Add | SharedAccessTablePermissions.Update |
                        SharedAccessTablePermissions.Query | SharedAccessTablePermissions.Delete
            };

            try
            {
                // Get the table's existing permissions.
                TablePermissions permissions = await table.GetPermissionsAsync();

                // Add the new policy to the table's permissions, and update the table's permissions.
                permissions.SharedAccessPolicies.Add(policyName, sharedPolicy);
                await table.SetPermissionsAsync(permissions);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
開發者ID:tamram,項目名稱:storage-table-dotnet-getting-started,代碼行數:34,代碼來源:Program.cs


注:本文中的Microsoft.WindowsAzure.Storage.Table.CloudTable.SetPermissionsAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。