Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set the CORS rules on an Azure Storage account to allow two domains, GET / POST, and cache for one hour
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Shared.Protocol;
public void SetCorsRules() {
var rule = new CorsRule
{
AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Post,
AllowedOrigins = new List<string>
{
"www.mysite.com",
"mysite.com"
},
MaxAgeInSeconds = 3600
};
var account = CloudStorageAccount.Parse("YourStorageConnectionString");
var client = account.CreateCloudBlobClient();
var properties = client.GetServiceProperties();
properties.Cors.CorsRules.Clear();
properties.Cors.CorsRules.Add(rule);
client.SetServiceProperties(properties);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.