简体   繁体   中英

Get connection string and password from Azure management

I am a user of Azure and want to get a connection string and email password from the azure management portal. I have put these two variables in the app settings and tried to get access to them on my website but the connection string always returns this error: The ConnectionString property has not been initialized.

Here is my C# code:

private string connectionString = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_bitverifydb");
private string emailPassword = Environment.GetEnvironmentVariable("APPSETTING_Password");

You can get your connection string and email password in your Azure App Settings by using the CloudConfigurationManager class in the "Microsoft.WindowsAzure.ConfigurationManager" namespace.

Note that you need to install the nuget package for this at the link below.

Microsoft Azure Configuration Manager

The sample code is as below:

private string connectionString = CloudConfigurationManager.GetSetting("SQLAZURECONNSTR_bitverifydb");
private string emailPassword = CloudConfigurationManager.GetSetting("APPSETTING_Password");

Hope this helps!

Make sure that you have added mentioned keys in your configuration files. You can refer the link below to get familiar with usage of CloudConfigurationManager. How to use the CloudConfigurationManager

It's not clear from your question which Azure platform you are using. Some other answers assumed it's CloudService. However, in a case, you are using AppService, it's the same code as .NET using System.Configuration

var connString = ConfigurationManager.ConnectionStrings["bitverifydb"].ConnectionString;
var password = ConfigurationManager.AppSettings["Password"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM