reverse
reverse

Reputation: 350

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 i.e to avoid code change throughout this promotion\env changes.

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

Upvotes: 2

Views: 443

Answers (3)

user585968
user585968

Reputation:

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

Upvotes: 1

Prawin
Prawin

Reputation: 1278

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

Upvotes: 3

Martin Brandl
Martin Brandl

Reputation: 58931

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

Upvotes: 2

Related Questions