I'm wondering if there is a way I can setup a .net mvc app the same way a .net core app can be setup with Key Vault.
I want to be able to pull secrets in my local development environment without provisioning an Azure Key Vault.
In a .net core app I was able to follow the above link and get everything working.
// ran this command in powershell
dotnet user-secrets set "db-connection-string" "db-connection-string-value"
Setup the key vault with an empty endpoint in Program.cs (this is just for testing).
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, builder) =>
{
var keyVaultEndpoint = GetKeyVaultEndpoint();
if (!string.IsNullOrEmpty(keyVaultEndpoint))
{
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
azureServiceTokenProvider.KeyVaultTokenCallback));
builder.AddAzureKeyVault(
keyVaultEndpoint, keyVaultClient, new DefaultKeyVaultSecretManager());
}
}
).UseStartup<Startup>()
.Build();
private static string GetKeyVaultEndpoint() => "";
And I am able to access my secret locally using the below code.
public void OnGet()
{
Message = "My key val = " + _configuration["db-connection-string"];
}
In my asp.net app I am able to pull secrets from an Azure Key Vault. I just don't want to have to do that when developing locally since each developer could have a slightly different connection string to their local database, and requiring them to use a Key Vault in Azure is going to be annoying and cause frustration. Maybe we shouldn't use Key Vault for "legacy" applications. Any help is appreciated.