Esempio n. 1
0
        public static async void SetUpAzureStorage(this IApplicationBuilder app)
        {
            string connectionString = AzureStorageConfiguration.GetConnectionString();

            BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            string[] directories = { "documents", "orders", "policy", "requests", "unknown" };

            foreach (var dir in directories)
            {
                CloudBlobContainer container = blobClient.GetContainerReference(dir);
                if (!container.Exists())
                {
                    await blobServiceClient.CreateBlobContainerAsync(dir);
                }
            }
        }
Esempio n. 2
0
        public static void AddCorsRuleForAzure(this IApplicationBuilder app)
        {
            var corsRule = new CorsRule()
            {
                AllowedHeaders = new List <string> {
                    "*"
                },
                AllowedMethods = CorsHttpMethods.Get,
                AllowedOrigins = new List <string> {
                    "https://localhost:5001"
                },
                MaxAgeInSeconds = 3600,
            };

            string connectionString               = AzureStorageConfiguration.GetConnectionString();
            CloudStorageAccount storageAccount    = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient     client            = storageAccount.CreateCloudBlobClient();
            ServiceProperties   serviceProperties = client.GetServiceProperties();
            CorsProperties      corsSettings      = serviceProperties.Cors;

            corsSettings.CorsRules.Add(corsRule);
            client.SetServiceProperties(serviceProperties);
        }