Я переношу свой код с .NET CORE 2.2 на .NET CORE 3.1. Я сталкиваюсь с приведенной ниже ошибкой при чтении строки подключения из appsettings.json.
"" Конфигурация "не содержит определения для" GetConnectionString ""
Я использую приведенный ниже код в startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
Мой appsettings.json выглядит следующим образом
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=abc.net;Initial Catalog=xyz;User ID=paper;Password=pencil"
},
"AllowedHosts": "*",
"serverSigningPassword": "key",
"accessTokenDurationInMinutes": 2
}
Есть ли способ прочитать эту строку подключения и другие переменные в appsettings.json