It's actually pretty simple.
First, add reference to Azure Storage Client library in your project. If you're using Nuget, the package you would want to install is WindowsAzure.Storage
.
After that, the function which sets the CORS settings is SetServiceProperties
. Here's the sample code to do so:
CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, accountKey), true);
var blobClient = storageAccount.CreateCloudBlobClient();
ServiceProperties blobServiceProperties = new ServiceProperties();
blobServiceProperties.Cors.CorsRules.Add(new CorsRule(){
AllowedHeaders = new List<string>() {"*"},
ExposedHeaders = new List<string>() {"*"},
AllowedMethods = CorsHttpMethods.Post | CorsHttpMethods.Put | ... Other Allowed Methods,
AllowedOrigins = new List<string>() {"http://yourdomain.com", "https://yourdomain.com", "blah", "blah", "blah"},
MaxAgeInSeconds = 3600,
});
blobClient.SetServiceProperties(blobServiceProperties);