Hi orlyo,
Thank you for reaching out to Microsoft Q & A forum.
Thank you for bringing this to our attention. We'll inform the internal team so the exercise can be updated in the future.
In the meantime, please update your Program.cs file with the revised code below. This approach eliminates the need for a Startup.cs file and follows the latest ASP.NET Core best practices:
using System;
using Azure.Identity;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var builder = WebApplication.CreateBuilder(args);
// Load secrets from Azure Key Vault
var vaultName = builder.Configuration["VaultName"];
if (!string.IsNullOrEmpty(vaultName))
{
var vaultUri = new Uri($"https://{vaultName}.vault.azure.net/");
builder.Configuration.AddAzureKeyVault(vaultUri, new DefaultAzureCredential());
}
// Register services
builder.Services.AddControllers();
var app = builder.Build();
// Configure HTTP request pipeline
app.MapControllers();
app.Run();
This setup removes the need for a Startup class, follows the latest pattern for ASP.NET Core, and works perfectly with your SecretTestController.cs file.
To create the Controllers folder and add the SecretTestController.cs file, run:
mkdir Controllers
touch Controllers/SecretTestController.cs
Then, paste the controller code and save.
If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.