Last Updated: November 19, 2020
·
5.608K
· artfulhacker

Azure CDN now Supports CORS

So we can finally host fonts in our Azure CDN!!!

This goes for anything else subject to cross-origin resource sharing restrictions.

So update your azure storage client library to (> 3.0) and do something like this:

var client = storageAccount.CreateCloudBlobClient();
var properties = client.GetServiceProperties();

var cors = new CorsRule();
cors.AllowedOrigins.Add("artfulhacker.com");
cors.AllowedMethods = CorsHttpMethods.Get;
cors.MaxAgeInSeconds = 3600;
properties.Cors.CorsRules.Add(cors);            

client.SetServiceProperties(properties);

If you want to allow any parent calling domain use this instead:

cors.AllowedOrigins.Add("*");

More information on this can be found here:

http://msdn.microsoft.com/en-us/library/windowsazure/dn535601.aspx

Related protips:

Common fonts for Windows & Mac

3 Responses
Add your response

I can believe it that a CDN is not configured by default to accept CORS from its own backend URL !

over 1 year ago ·

For me it doesn't seem to work. So I tried to apply with the asterisk (*) to be sure, but it still doesn't work. Running my app for second time I see with debugging the rule is applied.

over 1 year ago ·

Figured out blob storage does support the CORS rules, but the Azure CDN strips the CORS headers again.

over 1 year ago ·