Azure存储模拟器-Blob创建给出403禁止消息 [英] Azure storage emulator - blob creation gives 403 Forbidden message

查看:74
本文介绍了Azure存储模拟器-Blob创建给出403禁止消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Azure存储模拟器来处理Blob存储.我似乎无法使它正常工作,并且浪费了整整一天的时间尝试而没有成功.即使这是开发人员存储空间,我仍然收到403禁止错误.我希望这里有人可以帮助我.

I am attempting to use the Azure Storage Emulator to work with blob storage. I just cannot seem to get it to work and have wasted an entire day trying without success. I keep getting a 403 forbidden error even though this is developer storage. I am hoping someone here can assist me.

我以前曾在Azure上成功运行过相同的程序.但是,我的3个月试用期到期了,而我根本没有真正使用它,而现在我又回到了查看Azure的角度,我必须在存储模拟器上运行(将连接字符串更改为dev storage之后).

I had previously successfully run this same program on Azure. However my 3 month trial expired without me really using it at all, and now that I've returned to looking at Azure I must run on storage emulator (after changing the connection string to dev storage).

我将详细描述我所做的事情.

I will describe in detail what I have done.

首先让我向您保证,我已经安装了所有必要的东西(我认为):

First let me reassure you that I have everything necessary installed (I think):

我同时拥有Visual Studio 2012 Pro和Visual Studio 2012 Express for Web(免费).我已经使用Web平台安装程序安装了Azure所需的其他内容.如果我在添加/删除程序"中看到我有

I have both Visual Studio 2012 Pro and Visual Studio 2012 Express for Web (which is free). I have installed the additional stuff required for Azure using Web Platform installer. If I look in Add/Remove programs I see I have

  • 用于Microsoft Visual Studio 2012 -v2.1的Windows Azure工具
  • .NET -v2.1的Windows Azure库
  • Windows Azure模拟器-v2.1
  • Windows Azure创作工具-v2.1

如果愿意,我可以在VS2012中创建一个云项目,并且可以成功在模拟器上启动它.所以看来我的问题仅在于仿真器存储.

I am able to create a cloud project in VS2012 if I want to, and if I do it successfully launches on the emulator. So it seems my problem is only with emulator storage.

这是我所做的:

第1步.

我创建一个新的ASP.NET MVC4项目.我正在使用.NET Framework 4.5. 这将使用HomeController.cs和AccountController.cs创建基本项目模板.

I create a new ASP.NET MVC4 project. I'm using .NET framework 4.5. That creates the basic project template with a HomeController.cs and AccountController.cs

第2步.

我使用NuGet来获取"Windows Azure存储".我相信这会将WindowsAzure.Storage.dll版本2.0.6.1放入我的项目引用中. 除此之外,我看到我的参考文献还包括 -Microsoft.WindowsAzure.Configuration v2.0.0.0 -Microsoft.WindowsAzure.Diagnostics v2.1.0.0 -Microsoft.WindowsAzure.ServiceRuntime v2.1.0.0 -Microsoft.WindowsAzure.StorageClient v1.7.0.0

I use NuGet to get "Windows Azure Storage". I believe this puts WindowsAzure.Storage.dll version 2.0.6.1 in my project references. Aside from that I see that my references also include -Microsoft.WindowsAzure.Configuration v2.0.0.0 -Microsoft.WindowsAzure.Diagnostics v2.1.0.0 -Microsoft.WindowsAzure.ServiceRuntime v2.1.0.0 -Microsoft.WindowsAzure.StorageClient v1.7.0.0

第3步.

在Web.config文件中,我将以下标签添加到标签中

In Web.config file, I add the following tag within the tags

这基本上是每个人在使用仿真器时应该使用的帐户名和密钥.

This is basically the account name and key everyone is supposed to use when using the emulator.

第4步.

在HomeController.cs中,我创建一个动作.该操作应在Azure blob存储上创建一个容器,然后将文件上传到该容器.这是代码.如您所见,它几乎是您在初学者示例中找到的标准代码

In HomeController.cs I create an Action. This action is supposed to create a container on Azure blob storage, and upload a file to it. Here is the code. As you can see it is pretty much the standard code you find in beginner examples

    public ActionResult AddBlobToBlobContainerStorageEmulator()
    {
        // Retrieve storage account from connection string
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["EmulatorStorageConnectionString"]);

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve a reference to the previously created container. 
        CloudBlobContainer container = blobClient.GetContainerReference("myemulatortcont");

        // Create the container if it doesn't already exist.
        container.CreateIfNotExists();


        // Retrieve reference to a blob named "mytestblob".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("myemulatortestblob.jpg");

        // Create or overwrite the "mytestblob" blob with contents from a local file.
        using (var fileStream = System.IO.File.OpenRead(@"E:\TUTORIALS\Windows Azure\Azure NOTES and stuff\table.jpg"))
        {
            blockBlob.UploadFromStream(fileStream);
        }

        return Content("Blob uploaded to container on storage emulator");
    }


第5步.


Step 5.

我确保已启动计算模拟器: 开始>所有程序> Windows Azure>模拟器> Windows Azure Compute Emulator

I make sure the compute emulator is started : Start > All Programs > Windows Azure > Emulator > Windows Azure Compute Emulator

第6步.

仅此而已.我没有创建云项目或任何项目,因此在运行该项目时,它将根据项目属性(也称为IIS Express)在本地IIS Web服务器"上运行.

That's all. I did not create a cloud project or anything, so when I run this it will run on "Local IIS Web Server" as per the project properties (also known as IIS Express).

现在,我进入调试">开始调试",它会按预期在localhost:57810的浏览器窗口中启动站点.

Now I go to Debug > Start Debugging, and it launches the site in a browser window as expected at localhost:57810.

如果我导航到

http://localhost:57810/Home/AddBlobToBlobContainerStorageEmulator

它应该触发我的Action方法.

it should fire my Action method.

相反,我看到了

第118行为红色....因此,基本上无法创建容器.

Line 118 is in RED.... so basically the container cannot be created.

有人可以告诉我这里有什么问题吗?我是否需要以某种方式向开发存储模拟器添加权限?我不明白为什么会说禁止".

Can someone can tell me what is wrong here. Do I need to somehow add some permission to the development storage emulator? I don't understand why it says Forbidden.

我想知道我的计算机上是否存在某些问题,或者Azure之间是否存在某些冲突.我的项目中的dll版本对于开发模拟器是否有些不正确?还是v2.1中存在错误?

I was wondering if maybe there is some issue on my machine, or maybe there is some conflict between the Azure. Are the versions of the dlls in my project somehow incorrect for development emulator? Or maybe there is a bug in v2.1?

我已经确切地解释了我是如何制作项目的,但是如果有人想要尝试运行它,我愿意上传整个内容.

I've explained exactly how I made my project but I'd be willing to upload the entire thing if anyone is wants to just try running it.

感谢您提供的任何帮助.

Thank you for any help you can provide.

推荐答案

坦率地说,我对原始代码没有 工作.毕竟,Microsoft的MSDN文章 ( https://azure.microsoft.com/en-us/documentation/articles/storage-use-emulator/) 明确指出我们应该使用:

Quite frankly I am a little annoyed that the original code did not work. After all, the MSDN article by Microsoft (https://azure.microsoft.com/en-us/documentation/articles/storage-use-emulator/) clearly states we should use:

帐户名称:devstoreaccount1帐户密钥: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw ==

Account name: devstoreaccount1 Account key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

那为什么那没用呢?

基本上,存储模拟器的端点与云存储帐户的端点不同.例如,云存储帐户的默认Blob终结点为 http://[youraccount].blob.core.windows.net ,而存储模拟器的Blob终结点为 http://127.0.0.1:10000 .当您 公正 在连接字符串中指定存储模拟器的存储帐户名称和密钥时,存储客户端库将其视为云存储帐户,并尝试连接到使用您提供的帐户密钥.由于云中devstoreaccount1的密钥不是您提供的密钥,因此会出现403错误.

Basically storage emulator has different endpoints than the cloud storage account. For example, the default blob endpoint for a cloud storage account is http://[youraccount].blob.core.windows.net while the blob endpoint for storage emulator is http://127.0.0.1:10000. When you just specify the storage account name and key for the storage emulator in your connection string, storage client library treats it like a cloud storage account and tries to connect to http://devstoreaccount1.blob.core.windows.net using the account key you provided. Since the key for devstoreaccount1 in the cloud is not the one you provided, you get 403 error.

如果要使用帐户名和密钥连接到存储模拟器,则需要提供其他详细信息,例如不同的端点.因此,您的连接字符串将类似于:

If you want to connect to storage emulator using account name and key, you would need to provide additional details like different endpoints. So your connection string would be something like:

var connectionString = @"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;";

请注意我在连接字符串中指定的端点.

Notice the endpoints I have specified in the connection string.

var connectionString = "UseDevelopmentStorage=true";

上面的代码只是我上面指定的大连接字符串的简写形式.

The code above is just the short form of the big connection string I specified above.

希望这可以澄清您的疑问.

Hope this clarifies your doubt.

这篇关于Azure存储模拟器-Blob创建给出403禁止消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆