尝试在azure存储帐户/BBlob上设置cors时出现无尽错误

本文关键字:cors 设置 错误 无尽 BBlob azure 存储 | 更新日期: 2023-09-27 18:21:42

我正在尝试在一个azure存储blob帐户上设置cors,我已经向该帐户添加了CDN。原因是我可以从那里提供web字体并获得缓存。

我已经安装了nuget:的最新软件

已成功将"Microsoft.Data.Services.Client 5.6.0"添加到Impulse。正在将"Microsoft.WindowsAzure.ConfigurationManager 1.8.0.0"添加到Impulse。已成功将"Microsoft.WindowsAzure.ConfigurationManager 1.8.0.0"添加到Impulse。将"WindowsAzure.Storage 4.2.1"添加到Impulse。已成功将"WindowsAzure.Storage 4.2.1"添加到Impulse。

然后我使用了这个C#代码:

private void AzureCors()
        {
            CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("removed","removed"), true);
            var blobClient = storageAccount.CreateCloudBlobClient();
            ServiceProperties blobServiceProperties = new ServiceProperties();
            blobServiceProperties.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 = 3600 // 30 minutes 
            });
            blobClient.SetServiceProperties(blobServiceProperties);
        }

第一个错误是日志记录版本为null或为空。然而,根据MS的说法,这已经不再需要了,但我还是添加了它。然后我得到一个错误,即度量版本为null或为空,但这也不应该是必需的,不仅如此,而且实际上从4.2.1开始就停止了,而且我无论如何都无法设置度量,现在要使用的代码是HourMetrics,然而,填写一个小时的度量仍然会给度量带来错误。

那么,到底发生了什么,如果库外的存储都不起作用,我该怎么连接到azure存储呢?

顺便说一句,我已经在visualstudio2013中安装了最新的azure SDK昨天

不确定这是否是个问题?

尝试在azure存储帐户/BBlob上设置cors时出现无尽错误

试试这个代码:

    private void AzureCors()
    {
        CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("removed", "removed"), true);
        var blobClient = storageAccount.CreateCloudBlobClient();
        ServiceProperties blobServiceProperties = new ServiceProperties()
        {
            HourMetrics = null,
            MinuteMetrics = null,
            Logging = null,
        };
        blobServiceProperties.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 = 3600 // 30 minutes 
        });
        blobClient.SetServiceProperties(blobServiceProperties);
    }

基本上,当您创建ServiceProperties的实例时,所有属性(如HourMetrics等)都会被初始化。您需要做的是将不想更改的属性强制设置为null,这就是我在构造函数中所做的。