Questions tagged [appsettings]
appsettings.json (Application Settings) is a settings file. When configured, it can be used by .NET as a configuration source for settings you need at runtime & is automatically used by IIS to load all relevant web server settings. You can have multiple appsettings.json files for various environments in the format of appsettings.Environment.json e.g. appsettings.Production.json. Also used commonly to store logging settings like level & verbosity.
                                	
	appsettings
    
                            
                        
                    
            1,108
            questions
        
        
            958
            votes
        
        
            28
            answers
        
        
            1.3m
            views
        
    Reading settings from app.config or web.config in .NET
                I'm working on a C# class library that needs to be able to read settings from the web.config or app.config file (depending on whether the DLL is referenced from an ASP.NET web application or a Windows ...
            
        
       
    
            343
            votes
        
        
            24
            answers
        
        
            709k
            views
        
    Getting value from appsettings.json in .NET Core
                I am not sure what am I missing here, but I am not able to get the values from my appsettings.json in my .NET Core application. I have my appsettings.json as:
{
    "AppSettings": {
        &...
            
        
       
    
            238
            votes
        
        
            14
            answers
        
        
            381k
            views
        
    Automatically set appsettings.json for dev and release environments in asp.net core?
                I've defined some values in my appsettings.json for things like database connection strings, webapi locations and the like which are different for development, staging and live environments.
Is there ...
            
        
       
    
            227
            votes
        
        
            19
            answers
        
        
            218k
            views
        
    Opening the Settings app from another app
                Okay, I know that there are many question about it, but they are all from many time ago.
So. I know that it is possible because the Map app does it.
In the Map app if I turn off the localization for ...
            
        
       
    
            211
            votes
        
        
            18
            answers
        
        
            709k
            views
        
    AppSettings get value from .config file
                I'm not able to access values in configuration file.
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var clientsFilePath = config.AppSettings.Settings["...
            
        
       
    
            168
            votes
        
        
            9
            answers
        
        
            169k
            views
        
    How to check if an appSettings key exists?
                How do I check to see if an Application Setting is available?  
i.e. app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key ="someKey" ...
            
        
       
    
            152
            votes
        
        
            10
            answers
        
        
            158k
            views
        
    Read appsettings json values in .NET Core Test Project
                My Web application needs to read the Document DB keys from appsettings.json file. I have created a class with the key names and reading the Config section in ConfigureServices() as:
public Startup(...
            
        
       
    
            109
            votes
        
        
            14
            answers
        
        
            416k
            views
        
    Get ConnectionString from appsettings.json instead of being hardcoded in .NET Core 2.0 App
                I have the following class in NET Core2.0 App.
// required when local database does not exist or was deleted
public class ToDoContextFactory : IDesignTimeDbContextFactory<AppContext>
{
    ...
            
        
       
    
            102
            votes
        
        
            9
            answers
        
        
            273k
            views
        
    ConfigurationManager.AppSettings - How to modify and save?
                It might sound too trival to ask and I do the same thing as suggested in articles, yet it doesn't work as expected. Hope someone can point me to the right direction.
I would like to save the ...
            
        
       
    
            88
            votes
        
        
            8
            answers
        
        
            197k
            views
        
    how to get value from appsettings.json
                public class Bar
{
    public static readonly string Foo = ConfigurationManager.AppSettings["Foo"];
}
In the .NET Framework 4.x, I can use the ConfigurationManager.AppSettings ["Foo"] to get Foo in ...
            
        
       
    
            85
            votes
        
        
            4
            answers
        
        
            54k
            views
        
    Bind to a value defined in the Settings
                In WPF, Can I use binding with values defined in Settings? If this is possible, please provide a sample.
            
        
       
    
            77
            votes
        
        
            6
            answers
        
        
            118k
            views
        
    How to get values from appsettings.json in a console application using .NET Core?
                i'm creating a console application using .NET Core 3.1 and i would like to have an appsettings json to load all
environment, paths, variables,... at the beginning of the execution, and then get values ...
            
        
       
    
            76
            votes
        
        
            8
            answers
        
        
            68k
            views
        
    manual language selection in an iOS-App (iPhone and iPad)
                My question:
How can my iPhone-app tell the iOS, that the user did select a language in the apps preferences, that is different from the language set in the general settings?
Other formulation of the ...
            
        
       
    
            74
            votes
        
        
            3
            answers
        
        
            12k
            views
        
    What is the difference between app.config file and XYZ.settings file?
                I am actually in the learning phase of .NET related stuff and I was exploring how to save the application. I ended up writing my own class which saves the settings in an XML file and then I found that ...
            
        
       
    
            73
            votes
        
        
            17
            answers
        
        
            127k
            views
        
    ASP.NET Core appsettings.json update in code
                I am currently working on project using asp.net core v1.1, and in my appsettings.json I have:
"AppSettings": {
   "AzureConnectionKey": "***",
   "AzureContainerName": "**",
   "NumberOfTicks": ...
            
        
       
    
            73
            votes
        
        
            8
            answers
        
        
            47k
            views
        
    Why isn't there an XML-serializable dictionary in .NET?
                I need an XML-serializable dictionary. Actually, I now have two quite different programs that need one. I was rather surprised to see that .NET doesn't have one.
Can someone enlighten me, given how ...
            
        
       
    
            67
            votes
        
        
            3
            answers
        
        
            34k
            views
        
    How to read appsettings.json in my _layout.chtml
                I cannot seem to figure out how to read values from the appsettings.json in my _Layout.chtml file.
Is it not just available, something like this?
@Configuration["ApplicationInsights:...
            
        
       
    
            57
            votes
        
        
            2
            answers
        
        
            30k
            views
        
    Multiple AppSettings files, is it possible?
                I want to create 3 AppSettings config files:
Database.config
Messages.config
Global.config
And after add in my App.config:
<appSettings file="Database.config" />
<appSettings file="...
            
        
       
    
            56
            votes
        
        
            9
            answers
        
        
            55k
            views
        
    Find current country from iPhone device
                I have to get the current country in the iPhone settings. Can anyone tell me how to get the current country in iPhone application.
I have to use the current country for parsing the RSS feed in which ...
            
        
       
    
            56
            votes
        
        
            4
            answers
        
        
            38k
            views
        
    appSettings vs applicationSettings. appSettings outdated? [duplicate]
                I've got some questions about two ways to save settings in the web.config.
Appsettings:
Look in web.config
<appSettings>
 <add key="key1" value="value1"/>
 <add key="key2" value="...
            
        
       
    
            55
            votes
        
        
            7
            answers
        
        
            40k
            views
        
    Form submit resulting in "InvalidDataException: Form value count limit 1024 exceeded."
                I have created an mvc site and I'm posting a large amount of json form data (Content-Type:application/x-www-form-urlencoded)
back to the mvc controller. When I do this, I receive a 500 response that ...
            
        
       
    
            51
            votes
        
        
            26
            answers
        
        
            194k
            views
        
    Value cannot be null. Parameter name: connectionString appsettings.json in starter
                I am trying to write my connection string in my appsettings.json file and bring it into my startup file but I keep getting a Value cannot be null.
Parameter name: connectionString.  I have been using ...
            
        
       
    
            50
            votes
        
        
            2
            answers
        
        
            50k
            views
        
    How to hardcode and read a string array in appSettings.json?
                I use VSCode and NetCore 1.1.1.
I need to store several datapaths in my appsetting.json to let my console application know where to look for its data.
This is an extract of the appsettings.json file:...
            
        
       
    
            48
            votes
        
        
            7
            answers
        
        
            75k
            views
        
    Read values from local.settings.json in VS 2017 Azure Function development
                I am writing an Azure function in VS 2017. I need to set up a few custom configuration parameters. I added them in local.settings.json under Values.
{
   "IsEncrypted":false,
   "Values" : {
      "...
            
        
       
    
            42
            votes
        
        
            1
            answer
        
        
            4k
            views
        
    Adding settings class to a UWP app
                I'm developing a Universal Windows Platform app but there is no Settings template in Visual Studio.
How can I implement an easy, strongly typed and observable class that stores my settings in ...
            
        
       
    
            38
            votes
        
        
            6
            answers
        
        
            122k
            views
        
    Configuration.GetSection in Asp.Net Core 2.0 getting all settings
                I am trying to learn the various ways to retrieve configuration info so I can determine the best path for setting up and using configuration for an upcoming project.
I can access the various single ...
            
        
       
    
            36
            votes
        
        
            4
            answers
        
        
            25k
            views
        
    How to check if Configuration Section exists in .NET Core?
                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 ...
            
        
       
    
            36
            votes
        
        
            6
            answers
        
        
            44k
            views
        
    Restoring Window Size/Position With Multiple Monitors
                Many posts around about restoring a WinForm position and size.
Examples:
www.stackoverflow.com/questions/92540/save-and-restore-form-position-and-size
www.codeproject.com/KB/dialog/restoreposition....
            
        
       
    
            36
            votes
        
        
            2
            answers
        
        
            25k
            views
        
    How to Refresh a token using IHttpClientFactory
                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 ...
            
        
       
    
            36
            votes
        
        
            1
            answer
        
        
            21k
            views
        
    How to get Environment Variable in csproj file?
                I want to get the environment variable in csproj, because there I have a condition which exclude appsettings from publish.
I want this because, my appsettings didn't depends to Solution Configuration,...
            
        
       
    
            35
            votes
        
        
            2
            answers
        
        
            39k
            views
        
    Azure Application Settings not overriding my appsettings.json file values
                I have tried adding DefaultConnection from my appsettings.json file to Azure's Application Settings but Azure will not override the connection string. 
Any article or blog I can find states that all ...
            
        
       
    
            29
            votes
        
        
            6
            answers
        
        
            33k
            views
        
    Optional appsettings.local.json in (new format) visual studio project
                My app uses appsettings.json for some settings. If appsettings.local.json is present, that should override appsettings.json for whatever settings it contains. So far, no problem.
But I use git for ...
            
        
       
    
            29
            votes
        
        
            8
            answers
        
        
            92k
            views
        
    How to get the key value from the AppSettings.Config file?
                I'm trying to get my key value set in the appsettings.Config file but seems not working. 
This is what i wrote for that. The code is called from the constructor of an MDI file and its returning only ...
            
        
       
    
            28
            votes
        
        
            3
            answers
        
        
            27k
            views
        
    AppSettings.json for Integration Test in ASP.NET Core
                I am following this guide. I have a Startup in the API project that uses an appsettings.json configuration file.
public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var ...
            
        
       
    
            27
            votes
        
        
            7
            answers
        
        
            10k
            views
        
    Why do people consistently recommend using appConfig instead of using Settings files? (.NET)
                Very often I see the answer to the question like: "How should I store settings in my .NET app?" is to edit the app.config file by manually adding entries to the app.config (or web.config) like so:
&...
            
        
       
    
            26
            votes
        
        
            1
            answer
        
        
            46k
            views
        
    How do you put environmental variables in web.config?
                I am currently Following these tutorials, and I am wanting to call the clear text string from Azure's Application Settings for Web Apps. I am under the impression that environmental variables are used ...
            
        
       
    
            26
            votes
        
        
            1
            answer
        
        
            16k
            views
        
    How does reloadOnChange of Microsoft.Extensions.Configuration work for appsettings.json
                In two projects (a .NET Core Web API and a .NET Core WindowsService) I am using appsettings.json for the configuration.
var configuration = new ConfigurationBuilder()
          .SetBasePath(System.IO....
            
        
       
    
            25
            votes
        
        
            1
            answer
        
        
            36k
            views
        
    Access appsettings.json values in controller classes
                Having trouble figuring out how to read appsettings.json values outside of the startup.cs. What I would like to do is, for instance, is in the _Layout.cshtml, add the site name from the config:
For ...
            
        
       
    
            25
            votes
        
        
            3
            answers
        
        
            24k
            views
        
    JetBrains Rider - configure appsettings overrides
                I am trying JetBrains Rider for my existing .NET Core project. In the project I have several appsettings.json overrides:
appsettings.Development.json - for development
appsettings.Test.json - for ...
            
        
       
    
            24
            votes
        
        
            8
            answers
        
        
            10k
            views
        
    When to use .NET Settings vs config <appsettings>?
                Are there any recommendations on when to use Application settings (not per user settings) vs. .config file <appsettings>?
Update
Looking to understand some of the finer and important ...
            
        
       
    
            23
            votes
        
        
            2
            answers
        
        
            10k
            views
        
    Is it possible to have an ampersand sign in an appSettings key? error: web.config value is not defined
                I have the following appSettings section
<appSettings>
  <add key="Foo" value="http://foo.bar.com/?app=xxx&FormName=yyy" />
</appSettings>
But the IDE is giving me two errors:
...
            
        
       
    
            23
            votes
        
        
            6
            answers
        
        
            27k
            views
        
    Get the App.Config of another Exe
                I have an exe with an App.Config file. Now I want to create a wrapper dll around the exe in order to consume some of the functionalities.
The question is how can I access the app.config property in ...
            
        
       
    
            23
            votes
        
        
            4
            answers
        
        
            12k
            views
        
    ConfigurationManager.AppSettings["SettingName"] vs Properties.Settings.Default.SettingName when should I use each?
                What should dictate when I should use the configurationManager.AppSettings or the strongly typed settings that visual studio generates?  The strongly typed ones seem much more appropriate in most ...
            
        
       
    
            22
            votes
        
        
            7
            answers
        
        
            8k
            views
        
    How can I build an IOptionsMonitor<T> for testing?
                For the normal IOptions interface, you can manually build an instance e.g. this SO question.
Is there any equivalent way to make an IOptionsMonitor instance without using DI?
            
        
       
    
            22
            votes
        
        
            3
            answers
        
        
            35k
            views
        
    Reading integers from AppSettings over and over
                Some I do quite a lot of is read integers from AppSettings. What's the best way to do this?
Rather than do this every time:
int page_size; 
if (int.TryParse( ConfigurationManager.AppSettings["...
            
        
       
    
            21
            votes
        
        
            7
            answers
        
        
            53k
            views
        
    How to add configuration values in AppSettings.json in Azure functions. Is there any structure for it?
                What is the standard structure to add keys to appsettings.json?
Also, how to read those values in our run.csx?
Normally in app.config, we had ConfigurationManager.GetSettings["SettingName"];
Is there ...
            
        
       
    
            21
            votes
        
        
            6
            answers
        
        
            33k
            views
        
    Different application settings depending on configuration mode
                Is anyone aware of a way that I can set application (or user) level settings in a .Net application that are conditional on the applications current development mode? IE: Debug/Release
To be more ...
            
        
       
    
            20
            votes
        
        
            1
            answer
        
        
            17k
            views
        
    How to configure nested objects from appsettings.json in .NET Core?
                VS2015 Pro, .NET Core, Web Application.
I'm trying to figure out how to get objects out of appsettings, that have nested objects. I can do it with single level objects by creating a POCO with simple ...
            
        
       
    
            19
            votes
        
        
            2
            answers
        
        
            22k
            views
        
    Reading dll.config (not app.config!) from a plugin module
                I am writing a C# .NET 2.0 .dll that is a plug in to a Larger application.  The visual studio project for my module has a app.config file which is copied to a MyProj.dll.config along side of MyProj....
            
        
       
    
            18
            votes
        
        
            5
            answers
        
        
            33k
            views
        
    Can I set listen URLs in appsettings.json in ASP.net Core 2.0 Preview?
                I'm creating an ASP.net Core 2.0 app to run on the .net Core 2.0 runtime, both currently in their Preview versions. However, I cannot figure out how to have Kestrel use something other than the ...