0

I need to configure passwords to be fetched from Azure KeyVault in Azure Web App connection string. Can someone explain how to configure it ?

enter image description here

Thanks in advance !

I tried to get the passwords from key vault in Application settings and it worked fine , but couldn't able to integrate it in connection string.

3
  • Refer this documentation, you can use key vault references. Commented Dec 7, 2022 at 14:08
  • What is the version and framwork of the Web App you are using? Commented Dec 8, 2022 at 8:16
  • It is a Core or .Net framework Web App ? Commented Dec 8, 2022 at 10:15

1 Answer 1

0
  • Create an Azure KeyVault.
  • Create Secret. Copy the Secret Identifier of the Secret (this has to be used in Azure Configuration Connection String).

enter image description here

  • Provide necessary grants by using Access policies.
  • In Azure App Service => Configuration => Application Settings => Connection Strings, add the new Connection string setting.
  • For .NET Core App, the key name has to be MyNewConn.
  • For .NET Framework App, the name in the Azure App Connection String must be same as the key name in Local Configuration.

Thanks @Anand Sowmithiran for the Comment.

  • The value of the Connection string has to be @Microsoft.KeyVault(SecretUri=Secret Identifier).
  • Replace the Secret Identifier value with the value which we have copied from the KeyVault Secret (In Step 1).

enter image description here

For .NET Core Web App

appsettings.json

 "ConnectionStrings": {
    "MyNewConn": "LocalValue"
  }
string connectionString = configuration.GetConnectionString("MyNewConn");

For .NET Framework Web App

  • In Web.config file, you must have the below settings
 <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=*****" restartOnExternalChanges="false" requirePermission="false" />
  </configSections>
  <configBuilders>
    <builders>
      <add name="AzureKeyVault" vaultName="KeyVaultName" type="Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Azure, Version=1.0.0.0, Culture=neutral"  vaultUri="https://YourKeyVaultName.vault.azure.net" />
    </builders>
  </configBuilders>
  <connectionStrings>
    <add name="MyNewConn" connectionString="Retrieves the value from Azure App Service Connection String" providerName="System.Data.SqlClient" />
  </connectionStrings>
 var conn = ConfigurationManager.ConnectionStrings["MyNewConn"];    

Update

  • In Azure Key Vault, the step where we create the Secret, add the Secret value as the connection string. enter image description here.

Rest other steps are same.

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you @Harshitha, I already tried this way , Can you please share how use Application setting values in connection string ?
Its a Dotnetcore - 5.0 Web Application
Please share your appsettings.json file.
Please find the appsettings configuration for reference "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Server=tcp:sqlserver.database.windows.net,1433;Initial Catalog=Database;Persist Security Info=False;User ID=user;Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30" },
Please let me know what exactly you are trying to achieve.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.