A hypothetical web-site currently connects using:
public SqlConnection CreateConnection()
{
DbConnection connection = new SqlConnection();
connection.Conne
For .net Core and already having Azure Key Vault in place. Now it's extremely easy. Let's assume your connection string is in your appsettings.json:
{
"ConnectionStrings": {
"MyDatabase": "server=127.0.0.1;port=5678;database=mydb;user=FullMontyBurns;password=hunter2"
}
}
And you do your setup in Startup.cs
:
string connectionString = configuration.GetConnectionString("MyDatabase");
In Azure Key Vault, create a secret:
ConnectionStrings--MyDatabase
server=127.0.0.1;port=5678;database=mydb;user=FullMontyBurns;password=hunter2
The IConfiguration.GetConnectionString("MyDatabase")
now takes the value from the Key Vault.