Using appsettings.json in Asp.net core 6 Program.cs file

In case that we have in appsettings;

"settings": {
    "url": "myurl",
    "username": "guest",
    "password": "guest"
  }

and we have the class;

public class Settings
    {
        public string Url { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
    }

we can use also;

var settings = builder.Configuration.GetSection("Settings").Get<Settings>();

var url = settings.Url;

Reference

https://stackoverflow.com/questions/69390676/how-to-use-appsettings-json-in-asp-net-core-6-program-cs-file

FavoriteLoadingAdd to favorites
Spread the love

Author: Shahzad Khan

Software developer / Architect