[英]Endless Errors when trying to set cors on azure storage account / Blob
我正在嘗試在azure存儲blob帳戶上設置cors,我已經添加了CDN。 原因是我可以從那里提供Web字體並獲得緩存。
我已經安裝了來自nuget的最新軟件:
成功將“Microsoft.Data.Services.Client 5.6.0”添加到Impulse。 將“Microsoft.WindowsAzure.ConfigurationManager 1.8.0.0”添加到Impulse。 成功將“Microsoft.WindowsAzure.ConfigurationManager 1.8.0.0”添加到Impulse。 將“WindowsAzure.Storage 4.2.1”添加到Impulse中。 成功將“WindowsAzure.Storage 4.2.1”添加到Impulse。
然后我使用了這個C#代碼:
private void AzureCors()
{
CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("removed","removed"), true);
var blobClient = storageAccount.CreateCloudBlobClient();
ServiceProperties blobServiceProperties = new ServiceProperties();
blobServiceProperties.Cors.CorsRules.Add(new CorsRule(){
AllowedHeaders = new List<string>() { "*" },
AllowedMethods = CorsHttpMethods.Put | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Post,
AllowedOrigins = new List<string>() { "*" },
ExposedHeaders = new List<string>() { "*" },
MaxAgeInSeconds = 3600 // 30 minutes
});
blobClient.SetServiceProperties(blobServiceProperties);
}
第一個錯誤是日志記錄版本為null或為空。 但是根據MS不再需要,但無論如何我添加了它。 然后我得到一個錯誤,指標版本為空或空,但是這也不應該是必需的,但不僅如此,但實際上已從4.2.1中斷,我無法設置指標,並且代碼為現在使用的是HourMetrics,但填寫一小時指標仍然會給指標帶來錯誤。
那么究竟發生了什么,如果圖書館實際上沒有工作,我該如何連接到azure存儲呢?
不確定這是否是一個問題?
試試這段代碼:
private void AzureCors()
{
CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("removed", "removed"), true);
var blobClient = storageAccount.CreateCloudBlobClient();
ServiceProperties blobServiceProperties = new ServiceProperties()
{
HourMetrics = null,
MinuteMetrics = null,
Logging = null,
};
blobServiceProperties.Cors.CorsRules.Add(new CorsRule()
{
AllowedHeaders = new List<string>() { "*" },
AllowedMethods = CorsHttpMethods.Put | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Post,
AllowedOrigins = new List<string>() { "*" },
ExposedHeaders = new List<string>() { "*" },
MaxAgeInSeconds = 3600 // 30 minutes
});
blobClient.SetServiceProperties(blobServiceProperties);
}
基本上,當您創建ServiceProperties
的實例時,所有屬性(如HourMetrics
等)都會被初始化。 您需要做的是強制設置您不想更改為null
的屬性,這就是我在構造函數中所做的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.