Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Connection string with AzureKeyVault - Hybrid Blazor app

$
0
0

Used the local SQL connection string for development, starting testing and added KeyVault storage for the connection string in Azure...So in the project appsettings.json contains the connection string to Azure:

{"ConnectionStrings": {"DefaultConnectionLocal": "@AzureKeyVault(ConnectionStrings--DefaultConnection)"},"Logging": {"LogLevel": {"Default": "Information","Microsoft.AspNetCore": "Warning"    }  },"AllowedHosts": "*"

}

and with appsettings.Development.json:

{"ConnectionStrings": {"DefaultConnection": "Data Source=MY_LOCAL_SERVER\\SQLEXPRESS;..."},"DetailedErrors": true,"Logging": {"LogLevel": {"Default": "Information","Microsoft.AspNetCore": "Warning","Microsoft.Hosting.Lifetime": "Information","Microsoft.AspNetCore.SignalR": "Debug"    }  }}

Program.cs

var builder = WebApplication.CreateBuilder(args);var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));builder.Configuration.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());// Add services to the container.builder.Services.AddRazorComponents()    .AddInteractiveServerComponents()    .AddInteractiveWebAssemblyComponents();builder.Services.AddCascadingAuthenticationState();builder.Services.AddScoped<IdentityUserAccessor>();builder.Services.AddScoped<IdentityRedirectManager>();builder.Services.AddScoped<AuthenticationStateProvider, PersistingRevalidatingAuthenticationStateProvider>();builder.Services.AddAuthentication(options =>    {        options.DefaultScheme = IdentityConstants.ApplicationScheme;        options.DefaultSignInScheme = IdentityConstants.ExternalScheme;    })    .AddIdentityCookies();var conn = builder.Configuration.GetConnectionString("DefaultConnection");...

Without this line on Progam.cs

builder   .Configuration   .AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());

Load local connection string again...

What would be the correct way to use environment variables with Azure Key Vault in Blazor hybrid applications? (Without having to comment any line of code for test environments)


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>