c# - 设置的格式必须为 "name=value"。不知道该怎么办

标签 c# azure azure-storage

因此,我正在解析 Azure 存储帐户的连接字符串,当我到达使用连接字符串的应用程序页面时,编译器捕获一个异常,指出“设置必须采用“名称=值”的形式”。

这是否意味着我应该更正设置 appSettings 的 app.config 文件中的某些内容?如果是这样,您能立即发现我的格式有问题导致此异常吗?

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <appSettings>
            <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey" />
        <appSettings>
    </configuration>

以下是创建 CloudStorage 对象实例的代码:

CloudStorageAccount storageaccount = CloudStorageAccount.Parse ("StorageConnectionString");

        CloudTableClient tableClient = storageaccount.CreateCloudTableClient ();

        CloudTable austinBowlingAthletes = tableClient.GetTableReference ("austinBowlingAthletesTable");

最佳答案

您的"StorageConnectionString"应采用以下格式:

DefaultEndpointsProtocol=[http|https];AccountName=<YourAccountName>;AccountKey=<YourAccountKey>'如上所述here

另外,使用CloudConfigurationManager获取您的连接字符串:

string connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");

这带来了额外的好处,即当您的应用程序在本地运行时使用 app.config/web.config 或在云中运行时访问 azure 中的应用程序设置。请参阅this link

然后您应该能够解析连接字符串,并且无需在开发和生产环境之间修改 app.config/web.config 设置。

关于c# - 设置的格式必须为 "name=value"。不知道该怎么办,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36698509/

相关文章:

c# - 下载前显示 Azure 存储中的图像 - C#

c# - Azure表存储跨多个分区批量插入?

c# - 声明空字节 - 可空对象必须有一个值?

azure - HIVE 和 Parquet 文件

python - Azure blob 触发器错误 :The condition specified using HTTP conditional header(s) is not met

sql-server - Azure SQL (PaaS) 是否经过认证可以在 Microsoft Azure 托管的 Sharepoint 上使用?表现出色?

Azure Blob - 调用 UploadFile() 时出现 ArgumentNullException

c# - 如何将 XmlElementAttribute 用于 List<T>?

c# - 在 Visual Studio 中显示不友好的 HTTP 500 错误

C# - 如何使一系列方法调用成为原子的?