appsettings

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

泪湿孤枕 提交于 2020-05-28 14:01:13
问题 How can you check if a configuration section exists in the appsettings.json in .NET Core? Even if a section doesn't exist, the following code will always return an instantiated instance. e.g. var section = this.Configuration.GetSection<TestSection>("testsection"); 回答1: Query the children of Configuration and check if there is any with the name "testsection" var sectionExists = Configuration.GetChildren().Any(item => item.Key == "testsection")); This should return true if "testsection" exists,

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

送分小仙女□ 提交于 2020-05-28 14:00:50
问题 How can you check if a configuration section exists in the appsettings.json in .NET Core? Even if a section doesn't exist, the following code will always return an instantiated instance. e.g. var section = this.Configuration.GetSection<TestSection>("testsection"); 回答1: Query the children of Configuration and check if there is any with the name "testsection" var sectionExists = Configuration.GetChildren().Any(item => item.Key == "testsection")); This should return true if "testsection" exists,

How to get string array from core console appSettings.json file

风流意气都作罢 提交于 2020-05-15 08:47:25
问题 How do I return an string[] from the IConfigurationRoot object? File exists and is set to copy to output Code var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("settings.json", optional: false, reloadOnChange: false); _configuration = builder.Build(); var arr = _configuration["stringArray"]; // this returns null var arr1 = _configuration["stringArray:0"]; // this works and returns first element Settings.json { "stringArray": [ "myString1",

Is IIsreset always neccessary when storing my Web.Config appsettings in a separate file?

末鹿安然 提交于 2020-05-08 15:30:52
问题 I've got an ASP.Net app in which my AppSettings node from the Web.Config xml is stored in a separate file. So my Web.Config contains this: <appSettings file="AppSettings.config" /> Whenever I change a setting in there I have to do an iisreset to force the changes to kick in. In other words, my changes in this file aren't detected the same way changes to the Web.Config is. Does anyone know how I can make these changes take effect automatically, like it does with the Web.Config? Thanks! 回答1:

Is IIsreset always neccessary when storing my Web.Config appsettings in a separate file?

↘锁芯ラ 提交于 2020-05-08 15:29:50
问题 I've got an ASP.Net app in which my AppSettings node from the Web.Config xml is stored in a separate file. So my Web.Config contains this: <appSettings file="AppSettings.config" /> Whenever I change a setting in there I have to do an iisreset to force the changes to kick in. In other words, my changes in this file aren't detected the same way changes to the Web.Config is. Does anyone know how I can make these changes take effect automatically, like it does with the Web.Config? Thanks! 回答1:

How to Refresh a token using IHttpClientFactory

谁都会走 提交于 2020-04-29 15:48:43
问题 I am using IHttpClientFactory for sending requests and receiving HTTP responses from two external APIs using Net Core 2.2. I am looking for a good strategy to get a new access token using a refresh token that has been stored in the appsettings.json. The new access token needs to be requested when the current request returns 403 or 401 errors, When the new access and refresh token have been obtained, the appsettings.json needs to be updated with the new values in order to be used in subsequent

How to Refresh a token using IHttpClientFactory

给你一囗甜甜゛ 提交于 2020-04-29 15:44:47
问题 I am using IHttpClientFactory for sending requests and receiving HTTP responses from two external APIs using Net Core 2.2. I am looking for a good strategy to get a new access token using a refresh token that has been stored in the appsettings.json. The new access token needs to be requested when the current request returns 403 or 401 errors, When the new access and refresh token have been obtained, the appsettings.json needs to be updated with the new values in order to be used in subsequent

Setting Connection String as App Setting/Environment Variable in Azure Function

断了今生、忘了曾经 提交于 2020-04-17 17:56:33
问题 In my Azure Function, I have specified an Environment Variable/App Setting for a database connection string. I can use the Environment Variable when I run the Function locally on my Azure Data Science Virtual Machine using VS Code and Python. However, when I deploy the Function to Azure, I get an error: KeyValue is None, meaning that it cannot find the Environment Variable for the connection string. See error: Exception while executing function: Functions.matchmodel Result: Failure Exception:

Configure custom Column Options for Serilog Sinks MsSqlServer in AppSettings.json is not working

心已入冬 提交于 2020-03-03 08:55:31
问题 I'm trying to determine if it's possible to configure the column options for serilog sink mssqlserver in the appsettings.json file for an ASP.Net Core 3 project. besides not filling the custom columns, the database is also created in the standard way without these column, so I added them by hand. This could point to a configuration issue? The SQL to create the table CREATE TABLE [dbo].[logtable]( [Id] [int] IDENTITY(1,1) NOT NULL, [Message] [nvarchar](max) NULL, [MessageTemplate] [nvarchar]

Configure custom Column Options for Serilog Sinks MsSqlServer in AppSettings.json is not working

亡梦爱人 提交于 2020-03-03 08:55:11
问题 I'm trying to determine if it's possible to configure the column options for serilog sink mssqlserver in the appsettings.json file for an ASP.Net Core 3 project. besides not filling the custom columns, the database is also created in the standard way without these column, so I added them by hand. This could point to a configuration issue? The SQL to create the table CREATE TABLE [dbo].[logtable]( [Id] [int] IDENTITY(1,1) NOT NULL, [Message] [nvarchar](max) NULL, [MessageTemplate] [nvarchar]