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.
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):
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
- Windows Azure Tools for Microsoft Visual Studio 2012 -v2.1
- Windows Azure Libraries for .NET -v2.1
- Windows Azure Emulator -v2.1
- Windows Azure Authoring Tools -v2.1
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.
Here is what I have done:
Step 1.
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
Step 2.
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
Step 3.
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.
Step 4.
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:TUTORIALSWindows AzureAzure NOTES and stuffable.jpg"))
{
blockBlob.UploadFromStream(fileStream);
}
return Content("Blob uploaded to container on storage emulator");
}
Step 5.
I make sure the compute emulator is started : Start > All Programs > Windows Azure > Emulator > Windows Azure Compute Emulator
Step 6.
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).
Now I go to Debug > Start Debugging, and it launches the site in a browser window as expected at localhost:57810.
If I navigate to
http://localhost:57810/Home/AddBlobToBlobContainerStorageEmulator
it should fire my Action method.
Instead I see
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.
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.
See Question&Answers more detail:os