我正在尝试在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);
}
Run Code Online (Sandbox Code Playgroud)
第一个错误是日志记录版本为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);
}
Run Code Online (Sandbox Code Playgroud)
基本上,当您创建实例时ServiceProperties,所有属性HourMetrics等都会被初始化.你需要做的就是强行设置你不想改变的属性null,这就是我在构造函数中所做的.
| 归档时间: |
|
| 查看次数: |
369 次 |
| 最近记录: |