I'm migrating my code from .NET CORE 2.2 to .NET CORE 3.1. I'm encountering the below error while reading connection string from appsettings.json
"'Configuration' does not contain a definition for 'GetConnectionString'"
I'm using the below code in startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
My appsettings.json is as below
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=abc.net;Initial Catalog=xyz;User ID=paper;Password=pencil"
},
"AllowedHosts": "*",
"serverSigningPassword": "key",
"accessTokenDurationInMinutes": 2
}
Is there any way to read this connection string and other variables in appsettings.json