adsense

Sunday, October 22, 2023

ASP.NET Core 6/ASP.NET Core 7: Accessing Configuration during startup

 With the changes to Program.cs in .Net Core 7, we can still access confirmation options as below

appsettings.json

  "Settings": {

    "AccessTokenKey": "abcd123",

    "AccessTokenExpirySeconds": 3600,

    "RefreshTokenExpiryDays": 30

  } 

}

Program.cs

var builder = WebApplication.CreateBuilder();

ConfigurationManager config= builder.Configuration; // allows  access to  the config

IWebHostEnvironment environment = builder.Environment;// access the environment

                    var key = builder .Configuration["Settings:AccessTokenKey"]; 

Cheers,

Samitha 

No comments:

Post a Comment