2017-10-26 5 views
2

.NET Core 2.0でMicrosoft.WindowsAzure.Storage C#ライブラリを使用しています。Azureストレージエミュレータ - CORSを動的に設定するとサーバ認証エラーが発生する

"Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature".

public async void ConfigureCors() { 
     ServiceProperties serviceProperties = await this.blobClient.GetServicePropertiesAsync(); 

     serviceProperties.Cors = new CorsProperties(); 
     serviceProperties.Cors.CorsRules.Clear(); 
     serviceProperties.Cors.CorsRules.Add(new CorsRule() { 
      AllowedHeaders = allowedCorsHeaders, 
      ExposedHeaders = allowedCorsExposedHeaders, 
      AllowedOrigins = allowedCorsOrigin, 
      AllowedMethods = allowedCorsMethods, 
      MaxAgeInSeconds = allowedCorsAgeInSeconds 
     }); 
     await blobClient.SetServicePropertiesAsync(serviceProperties); 
    } 

私が直接、ローカルサーバー上のアップロードファイル用のSASキーを生成することができるよ、しかし、ことはできません:私はAzureストレージエミュレータで動的にCORSを設定しようとしているが、エラーを取得しています。このライブラリを使用して C#コードでストレージにアクセスできるようにCORSを動的に構成します。

Azure Storage Cloudを使用すると上記のコードが正常に動作していますが、ローカルエミュレータがこのエラーをスローしています。

バージョン情報:

WindowsAzure.Storageバージョン8.4.0

のWindows Azureストレージエミュレーターバージョン5.2.0.0

AzureのストレージExplorerのバージョンは0.9.01

です接続に使用された証明書:

AccountName = devstoreaccount1;

AccountKey = Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuF q2UVErCz4I6tq/K1SZFP TOtr/KBHBeksoGMGw ==;

答えて

0

あなたの説明によると、私は自分の側にテストデモを作成しました。それはうまくいく。

Server failed to authenticate the requestエラーが発生したのは間違ったazureストレージパッケージのバージョンとストレージエミュレータのバージョンです。

ストレージバージョンを8.4.0に、ストレージエミュレータバージョンを5.2にアップデートしてから、もう一度試してみることをお勧めします。私のテストのデモについて

詳細、あなたはコード以下を参照できます。

 CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true"); 

     CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); 



     ServiceProperties serviceProperties = blobClient.GetServicePropertiesAsync().Result; 

     serviceProperties.Cors = new CorsProperties(); 
     serviceProperties.Cors.CorsRules.Clear(); 
     serviceProperties.Cors.CorsRules.Add(new CorsRule() 
     { 
      AllowedHeaders = new List<string>() { "*" }, 
      ExposedHeaders = new List<string>() { "*" }, 
      AllowedOrigins = new List<string>() { "*" }, 
      AllowedMethods = CorsHttpMethods.Put | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Post, 
      MaxAgeInSeconds = 1800 
     }); 
     var re = blobClient.SetServicePropertiesAsync(serviceProperties); 

結果:

enter image description here

+0

WindowsAzure.Storageバージョンは8.4.0 のWindows Azureストレージエミュレーターバージョン5.2です.0.0 Azureストレージエクスプローラバージョンは0.9.01 –

+0

接続に使用される資格情報:AccountName = devstoreaccount1; AccountKey = Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UverCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw ==; –

関連する問題