问题描述
我想一个Azure的网站连接到Azure的BLOB(在这里我打算举办一个容器的一些文件,然后从我的网站抓住他们)。
I'm trying to connect an Azure website to an Azure blob (where I intend to host some files in a container and then grab them from my website).
我开始了这个教程:
的
我部署了我的网站,然后开始按照本教程:
http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/#setup-connection-string
I deployed my website, and then started following this tutorial:http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/#setup-connection-string
由于我使用的Azure网站,我增加了以下code到我的web.config文件(WebApplication1项目中)。也有意见文件夹下的web.config文件,但我没有修改。
Since I was using an Azure website, I added the following code to my web.config file (under the WebApplication1 project). There is also a web.config file under the Views folder but I didn't modify that.
<configuration>
<appSettings>
<add key="StorageConnectionString"
value="DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key" />
</appSettings>
</configuration>
我也跟着教程中的所有步骤,并安装相关的NuGet包,然后包括在我的控制器/ HomeController.cs
文件中的这些命名空间:
I followed all the steps in the tutorial and installed the relevant NuGet packages and then included these namespaces in my Controllers/HomeController.cs
file:
using System.Configuration;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
然后,我添加了的ActionResult指数()
办法(默认情况下运行),下面的语句。
Then I added the following statement in the ActionResult Index()
method (which runs by default).
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
当我尝试和运行解决方案,现在我得到这个错误:
When I try and run the solution, I now get this error:
我也试过直接把价值的 StorageConnectionString
(用我的帐户名和密钥),而不是引用它在下面的语句:
I also tried directly putting the value of the StorageConnectionString
(with my account name and key) instead of referencing to it in the following statement:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key"].ConnectionString);
我仍然得到同样的错误。我似乎无法找到在互联网上的任何东西。任何想法?
I still get the same error. I can't seem to find anything on the internet. Any ideas?
谢谢!
推荐答案
您在你的code一个根本的错误。
You have a fundamental mistake in your code.
首先,你设置AppSetting:
First you set an AppSetting:
<configuration>
<appSettings>
<add key="StorageConnectionString"
value="DefaultEndpointsProtocol=https;AccountName=account- name;AccountKey=account-key" />
</appSettings>
</configuration>
然后尝试得到一个连接字符串:
Then you try to get a connection string:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
这根本不起作用。当设置AppSetting,你需要阅读AppSetting。当您设置的ConnectionString,你需要阅读的连接字符串。
This will simply not work. When set AppSetting, you need to read AppSetting. When you set ConnectionString, you need to read Connection String.
所以,解决的办法是只保留在web.config原样,并更改行你在哪里得到的存储账户:
So, the solution to be just keep the web.config as is, and change the line where you get storage account to:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
或保留线连接字符串,但改变的web.config:
Or keep your line for Connection strings but change web.config to:
<configuration>
<connectionStrings>
<add name="StorageConnectionString"
connectionString="DefaultEndpointsProtocol=https;AccountName=account- name;AccountKey=account-key" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
当然,你必须把你的真实值云存储账户和存储帐户密钥(帐户名称
根本不会工作)。
这篇关于连接Azure的斑点与Azure的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!