C# 使用Azure存储模拟器测试开发

C# 使用Azure存储模拟器测试开发,c#,azure,asp.net-core,azure-storage,azure-emulator,C#,Azure,Asp.net Core,Azure Storage,Azure Emulator,我正在使用Azure Storage Emulator版本在windows 10-x64和WindowsAzure.Storage 9.1.1上测试asp.net core 2.1-rc1 web应用程序 我已经按照此指南安装了Azure存储模拟器 当我尝试创建blob容器时,出现以下异常: Microsoft.WindowsAzure.Storage.StorageException: Server failed to authenticate the request. Make sure

我正在使用Azure Storage Emulator版本在windows 10-x64和WindowsAzure.Storage 9.1.1上测试asp.net core 2.1-rc1 web应用程序

我已经按照此指南安装了Azure存储模拟器

当我尝试创建blob容器时,出现以下异常:

Microsoft.WindowsAzure.Storage.StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token) in C:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\WindowsRuntime\Core\Executor\Executor.cs:line 316
at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExistsAsync(BlobContainerPublicAccessType accessType, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) in C:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\WindowsRuntime\Blob\CloudBlobContainer.cs:line 165

Request Information
RequestID:c4a44dcc-301e-002e-5ad0-f2637a000000
RequestDate:Wed, 23 May 2018 22:02:36 GMT
StatusMessage:Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
ErrorCode:AuthenticationFailed
ErrorMessage:Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:c4a44dcc-301e-002e-5ad0-f2637a000000
Time:2018-05-23T20:02:36.9987818Z
我在例外附加信息中发现了这一点:-

"The MAC signature found in the HTTP request 'NeZGAEspShTRdpc/zFH++pS9YChlOczzEg0vcVGXF10=' is not the same as any computed signature. Server used following string to sign: 'PUT\n\n\n\n\n\n\n\n\n\n\n\nx-ms-client-request-id:e4b5b43c-ba27-45b1-8545-19db1c16a160\nx-ms-date:Wed, 23 May 2018 19:10:31 GMT\nx-ms-version:2017-07-29\n/devstoreaccount1/admins\nrestype:container'."
这是我的密码:-

public static async Task InitializeContainersAsync()
{
    try
    {
        //Use the emulator default credenitals
        var credentials = new StorageCredentials("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");
        CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, false);

        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        CloudBlobContainer container = blobClient.GetContainerReference("testing_container");

        await container.CreateIfNotExistsAsync();
    }
    catch (StorageException ex)
    {
        Console.WriteLine(ex);
    }
}

如果要使用存储仿真器,实际上有两个选项

  • 最简单的方法是使用connectionstring
    UseDevelopmentStorage=true
  • 从应用程序连接到存储仿真程序的最简单方法是在应用程序的配置文件中配置一个连接字符串,该字符串引用快捷方式UseDevelopmentStorage=true。下面是app.config文件中存储仿真程序的连接字符串示例:


    如果要使用存储仿真器,实际上有两个选项

  • 最简单的方法是使用connectionstring
    UseDevelopmentStorage=true
  • 从应用程序连接到存储仿真程序的最简单方法是在应用程序的配置文件中配置一个连接字符串,该字符串引用快捷方式UseDevelopmentStorage=true。下面是app.config文件中存储仿真程序的连接字符串示例:


    您使用的是哪个版本的存储模拟器?我使用的是v 5.3.17342.2050。您对此项目有应用程序见解吗?我记得有一个问题,app insights向请求中注入头,导致MAC签名无效。不,项目中不包括application insights您使用的是哪个版本的存储模拟器?我使用的是v 5.3.17342.2050。您在这个项目中有application insights吗?我记得有一个问题,app insights向请求中注入头,导致MAC签名无效。不,application insights不包括在项目中。谢谢你的回答,添加端点解决了StorageException,但我遇到了另一个与此链接中所述相同的异常:-将emulator更新为最新版本解决了问题。感谢您的回答,添加端点解决了StorageException,但我遇到了另一个与此链接中所述相同的异常:-将emulator更新为最新版本解决了问题。
    <appSettings>
      <add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
    </appSettings>
    
    DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
    AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
    BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
    TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;
    QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;