Explore Courses Blog Tutorials Interview Questions
0 votes
in Azure by (13.1k points)
I have a blob storage in Microsoft Azure, and have some set of files present in the container, now, I want to access those files using jquery, but it is throwing error because of CORS.

Can anyone help me how exactly, I can able to configure CORS in azure blob storage?

1 Answer

0 votes
by (26.7k points)

If you want to set CORS programmatically, then given below is the code.

private static void InitializeCors()


     // CORS should be enabled once at service startup

     // Given a BlobClient, download the current Service Properties 

     ServiceProperties blobServiceProperties = BlobClient.GetServiceProperties();

     ServiceProperties tableServiceProperties = TableClient.GetServiceProperties();

     // Enable and Configure CORS



     // Commit the CORS changes into the Service Properties




private static void ConfigureCors(ServiceProperties serviceProperties)


    serviceProperties.Cors = new CorsProperties();

    serviceProperties.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 = 1800 // 30 minutes



Also, if you want to configure it using some tools then these are the tools: Azure Storage Explorer, Cerebrata Azure Management Studio, Cloud Portam.

Want to become an Azure Expert? join Azure Training now!!

Browse Categories