Endless errors when trying to install cors on azure storage account / Blob
I am trying to set up cors on an azure storage blob account that I have added a CDN. the reason is that i can serve web fonts from there and get cached.
I installed the latest software from nuget:
Successfully added "Microsoft.Data.Services.Client 5.6.0" to Impulse. Adding "Microsoft.WindowsAzure.ConfigurationManager 1.8.0.0" to Impulse. Successfully added "Microsoft.WindowsAzure.ConfigurationManager 1.8.0.0" to Impulse. Adding "WindowsAzure.Storage 4.2.1" to Impulse. Successfully added "WindowsAzure.Storage 4.2.1" to Impulse.
Then I used this C # code:
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);
}
This first error: the journal version is blank or empty. however this according to MS is no longer required, but I added it anyway. Then I get the error that the Metrics version is empty or empty, however this is not required either, but not only that, but actually discontinued from 4.2.1 and I still cannot set the metrics and the code is now using HourMetrics. however, filling in hourly metrics still gives error for metrics.
So what's going on, how the hell am I supposed to connect to the azure repository if none of the libraries are running?
as a sideline i installed the latest azure SDK in visual studio 2013 yesterday
Not sure if this might be the problem?
source to share
Try this code:
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);
}
Basically, when you instantiate ServiceProperties
, all properties of the type HourMetrics
, etc. are initialized. What you need to do is force the properties you don't want to change to null
, and that's what I did in the constructor.
source to share