"ConnectionStrings": {
"Annuaire": "Server=SORA11\\MSSQL_APP;Database=Annuaire;User ID=****;Password=*****;Persist Security Info=False"
}
https://stackoverflow.com/questions/39083372/how-to-read-connection-string-in-net-core
In Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
// Add the whole configuration object here.
services.AddSingleton
}
In your controller add a field for the configuration and a parameter for it on a constructor
private readonly IConfiguration configuration;
public HomeController(IConfiguration config)
{
configuration = config;
}
Now later in your view code you can access it like:
connectionString = configuration.GetConnectionString("DefaultConnection");