I recently deployed a .NET 8 Application in Azure but got the HTTP Error 500.30 - ASP.NET Core app failed to start
when navigating to the default URL Azure provides. I have a couple of Azure services that the application is consuming. Blob Storage, Key Vaults (KV), and SQL database.
After some investigation, I came to the conclusion that it had to do with networking issues, however, I have set the network to be public because the website can be accessed by anyone. Just not the DB and KV. I don't believe that the DB could cause the 500 error but I do believe now that KV could be the culprit.
My question is in two parts. Is KV the reason my application is not running? If so, how to fix it? I see that I may need to provide some sort of access policy, possibly? Any help is appreciated.
Here is how I'm trying to access the KV in the Program.cs
file.
var builder = WebApplication.CreateBuilder(args);
string keyVaultUri = builder.Configuration["KeyVaultConfig:KVUrl"];
var credentials = new DefaultAzureCredential();
var client = new SecretClient(new Uri(keyVaultUri), credentials);
string tenantId = "TenantId";
string blobStorageName = "BlobStorageName";
string blobConnString = "BlobConnectionString";
string azureConnectionString = "AzureSQLConnectionString";
KeyVaultSecret blobName = await client.GetSecretAsync(blobStorageName);
KeyVaultSecret blobConnectionString = await client.GetSecretAsync(blobConnString);
KeyVaultSecret azConnString = await client.GetSecretAsync(azureConnectionString);
string dbValue = azConnString.Value;
builder.Configuration["BlobConfig:BlobStorageName"] = blobName.Value;
builder.Configuration["BlobConfig:BloblConnectionString"] = blobConnectionString.Value;
builder.Services.AddDbContext<SuperAnchorDBContext>(options => options.UseSqlServer(dbValue));
I have found my solution. I forgot to add the Client Id, Tenant Id, and CLient Secret in the environment variables in the app services. Added those and now it is working properly