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


C# CloudTable.GetSharedAccessSignature方法代碼示例

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


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

示例1: RequestSasToken

		static string RequestSasToken(CloudTable table, string customerId)
		{
			// Omitting any authentication code since this is beyond the scope of
			// this sample code

			// creating a shared access policy that expires in 1 day.
			// No start time is specified, which means that the token is valid immediately.
			// The policy specifies full permissions.
			SharedAccessTablePolicy policy = new SharedAccessTablePolicy()
			{
				SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
				SharedAccessExpiryTime = DateTime.UtcNow.AddDays(1.0),
				Permissions = SharedAccessTablePermissions.Add
					| SharedAccessTablePermissions.Query
					| SharedAccessTablePermissions.Update
					| SharedAccessTablePermissions.Delete
			};

			// Generate the SAS token. No access policy identifier is used which
			// makes it a non-revocable token
			// limiting the table SAS access to only the request customer's id
			string sasToken = table.GetSharedAccessSignature(
				policy   /* access policy */,
				null     /* access policy identifier */,
				customerId /* start partition key */,
				null     /* start row key */,
				customerId /* end partition key */,
				null     /* end row key */);

			return sasToken;
		}
開發者ID:King-of-Spades,項目名稱:xamarin-samples,代碼行數:31,代碼來源:Table.cs

示例2: GetTableSasUri

        /// <summary>
        /// Returns a URI containing a SAS for the table.
        /// </summary>
        /// <param name="table">A CloudTable object.</param>
        /// <param name="storedPolicyName">A string containing the name of the stored access policy. If null, an ad-hoc SAS is created.</param>
        /// <returns>A string containing the URI for the table, with the SAS token appended.</returns>
        private static string GetTableSasUri(CloudTable table, string storedPolicyName = null)
        {
            string sasTableToken;

            // If no stored policy is specified, create a new access policy and define its constraints.
            if (storedPolicyName == null)
            {
                // Note that the SharedAccessTablePolicy class is used both to define the parameters of an ad-hoc SAS, and 
                // to construct a shared access policy that is saved to the table's shared access policies. 
                SharedAccessTablePolicy adHocPolicy = 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
                };

                // Generate the shared access signature on the table, setting the constraints directly on the signature.
                sasTableToken = table.GetSharedAccessSignature(adHocPolicy, null);

                Console.WriteLine("SAS for table (ad hoc): {0}", sasTableToken);
                Console.WriteLine();
            }
            else
            {
                // Generate the shared access signature on the table. In this case, all of the constraints for the
                // shared access signature are specified on the stored access policy, which is provided by name.
                // It is also possible to specify some constraints on an ad-hoc SAS and others on the stored access policy.
                // However, a constraint must be specified on one or the other; it cannot be specified on both.
                sasTableToken = table.GetSharedAccessSignature(null, storedPolicyName);

                Console.WriteLine("SAS for table (stored access policy): {0}", sasTableToken);
                Console.WriteLine();
            }

            // Return the URI string for the table, including the SAS token.
            return table.Uri + sasTableToken;
        }
開發者ID:tamram,項目名稱:storage-table-dotnet-getting-started,代碼行數:44,代碼來源:Program.cs


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