Settings must be of the form “name=value”. No idea what to do

前端 未结 3 646
名媛妹妹
名媛妹妹 2021-01-17 15:28

So I\'m parsing a connection string for an Azure Storage Account and when I get to the page of the app that uses the connection string, the compiler catches an exception sta

相关标签:
3条回答
  • 2021-01-17 16:11

    The reason you're running into this error is because you're asking CloudStorageAccount.Parse method to literally parse "StorageConnectionString" string instead of the value of this setting stored in app.config file. What you need to do instead is read the value of this setting from the config file. For example, in a console application I would do something like this:

             var appSettingsReader = new AppSettingsReader();
             var connectionString = (string) appSettingsReader.GetValue("StorageConnectionString", typeof(string));
             CloudStorageAccount storageaccount = CloudStorageAccount.Parse(connectionString);
    

    I had to add a reference for System.Configuration assembly to do so.

    0 讨论(0)
  • 2021-01-17 16:16

    Add a reference to System.Configuration.dll and add using System.Configuration; in the file.

    Then change your first line to this:

    CloudStorageAccount storageaccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
    

    You need to get the value, not just pass the key to Parse.

    0 讨论(0)
  • 2021-01-17 16:18

    Your "StorageConnectionString" should be in the format of:

    DefaultEndpointsProtocol=[http|https];AccountName=<YourAccountName>;AccountKey=<YourAccountKey>' as described here

    Also, use CloudConfigurationManagerto obtain your connection string:

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

    This gives the added benefit of either using app.config/web.config when your app is running locally or accessing your app setting in azure when running in the cloud. See this link

    Then you should beable to parse the connection string and have the benefit of not having to modify app.config/web.config settings between development & production environments.

    0 讨论(0)
提交回复
热议问题