简体   繁体   中英

Accessing Storage account programmatically

In my c# solution I am accessing my storage account through a connection string.

Issue -

  1. right now the cloud solution is in dev
  2. when the solution will be promoted to qa\prod - that string will change. Is there an alternative better way to manage this ie to avoid code change throughout this promotion\env changes.

one way i was thinking was use of vault.. any other idea? Please guide. Thanks.

I assume you are talking about a Web App where you are using Storage Account Connection string.

Usually, it's a good practice to have your connection string in a config file (web.config for.Net Framework and appsettings.json for .net core).

However, though these work in Azure App Service, they are kind of deprecated. So, you need to create App Settings / Connection Strings (go to Configuration blade in App Service) for your Storage Connection.

You didn't mention what kind of application you have in your solution. Based on the type you can use the below appropriate technique to access the App Settings/ connection strings.

  1. .Net Framework - ConfigurationManager namespace
  2. .Net Core - IConfiguration

Thanks, Praveen

There are at least two things you should do.

  1. Use the Options pattern in ASP.NET Core to retrieve your settings like connections strings. This will, for example, use your appsettings.json if you work locally and it will overwrite these settings with environment variables you are setting in Azure. This mean, you don't have to worry where your settings come from.

  2. Configure connection strings in your App Service application.

Also consider using Key Vault references for App Service settings

I see you are using Azure DevOps.

The old "config transforms" of yesteryear are arguably deprecated now with continuous deployment (CD). Essentially your connection string represents a "secret" or at least something that is stage-dependent and generally stage dependant items should not be part of the source code's repository. Sure you can put them in but its much easier to manage in CD.

Instead, whoever is defining the CD pipeline defines it in other means such as DevOps CD variables and injects it into your config after the code has been compiled but just prior to deployment

More

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