我正在尝试在 azure 存储 blob 帐户上设置 cors,我已向该帐户添加了 CDN。
原因是这样我可以从那里提供网络字体并获取缓存。
我已经安装了 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);
}
第一个错误是日志记录版本为空或为空。然而,根据 MS 的说法,这不再是必需的,但我还是添加了它。然后我收到一个错误,指出 Metrics Version 为 null 或为空,但这也不应该是必需的,但不仅如此,而且实际上从 4.2.1 开始就停止了,我无论如何都无法设置指标,并且代码为现在使用的是HourMetrics,但是,填写一个小时指标仍然会出现指标错误。
那么发生了什么事,如果库都没有真正工作的话,我到底应该如何连接到天蓝色存储?
作为旁注,我昨天已将最新的 azure SDK 安装到 Visual Studio 2013 中
不确定这是否是一个问题?
试试这个代码:
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
这就是我在构造函数中所做的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)