Configuration.GetSection in Asp.Net Core 2.0 getting all settings

I understand the answer has been accepted. However, providing proper example code, just in case anyone looking to understand a bit more… It is quite straight forward to bind custom strong type configuration. ie. configuration json looks like below { “AppSettings”: { “v”: true, “SmsSettings”: { “FromPhone”: “9145670987”, “StartMessagePart”: “Dear user, You have requested info … Read more

How to check if Configuration Section exists in .NET Core?

Since .NET Core 2.0, you can also call the ConfigurationExtensions.Exists extension method to check if a section exists. var section = this.Configuration.GetSection(“testsection”); var sectionExists = section.Exists(); Since GetSection(sectionKey) never returns null, you can safely call Exists on its return value. It is also helpful to read this documentation on Configuration in ASP.NET Core.

How to Refresh a token using IHttpClientFactory

Looks like you need DelegatingHandler. In two words you can “intercept” your http request and add the Authorization header, then try to execute it and if token was not valid, refresh token and retry one more time. Something like: public class AuthenticationDelegatingHandler : DelegatingHandler { protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var … Read more

Restoring Window Size/Position With Multiple Monitors

Try this code. Points of interest: Checks if the window is (partially) visible on any screen’s working area. E.g. dragging it behind the task bar or moving it completely offscreen resets the position to windows default. Saves the correct bounds even if the Form is minimized or maximized (common error) Saves the WindowState correctly. Saving … Read more

How to hardcode and read a string array in appSettings.json?

Indexer of a section returns string by exact key match, and since array values have keys with postfixes, there is nothing to match given key and you are getting null. To get it work you may use something like this var section = configuration.GetSection($”{APP_SETTINGS_SECTION}:{APP_SETTINGS_KEY}”); var folders = section.Get<string[]>(); And check this for more options.

Value cannot be null. Parameter name: connectionString appsettings.json in starter

First of all, the “Data”: { “ConnectionStrings”: { “DefaultConnection”: “Data Source=server;Initial Catalog=dbase;Trusted_Connection=True;MultipleActiveResultSets=true”}, } Is slightly different from the structure you get when you add a “Asp.NET Configuration File” in Visual Studio. When you do that you get “ConnectionStrings”: { “DefaultConnection”: “Data Source=server;Initial Catalog=dbase;Trusted_Connection=True;MultipleActiveResultSets=true”}, without the “Data” JavaScript Object. So that’s why the extension method isn’t … Read more