configurationmanager

ConfigurationManager.AppSettings Caching

旧城冷巷雨未停 提交于 2019-11-29 04:35:56
问题 We know that IIS caches ConfigurationManager.AppSettings so it reads the disk only once until the web.config is changed. This is done for performance purposes. Someone at: http://forums.asp.net/p/1080926/1598469.aspx#1598469 stated that .NET Framework doesn't do the same for app.config, but it reads from the disk for every request. But I find it hard to believe, 'cause it would be slower. Please tell me that he is wrong or I'll have to fix every Console/Windows Forms/Windows Services I wrote.

How to read values from multiple Configuration file in c# within a single project?

狂风中的少年 提交于 2019-11-29 02:07:13
Here in my project I have two application configuration files called app.config and accessLevel.config . Now using the OpenExeConfiguration I was able to access the app.config.exe file but not the accessLevel.config . Please help on this. The main reason I have 2 config files is to show the difference and make the code simple. I need to read the values from the accessLevel.config in my C# code. Tried the below code but no use: System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.File = "App2.config"; Michael See

Can someone provide a quick App.config/Web.config tutorial?

假装没事ソ 提交于 2019-11-28 23:58:56
I've used these two configuration files many times before, but I've never taken the time to fully understand how they really work. As most people do, I understand the basics in how to call WebConfigurationManager.AppSettings["key"] to get config values. Here are some questions I came up with: What happens when you reference a configuration value within a class library, and the library is part of a bigger solution? Does the app.config need to be copied to the output directory in order for the variables to be found? (I assume yes) Can you directly use a configuration value from an app.config in

How to load application settings to NHibernate.Cfg.Configuration object?

社会主义新天地 提交于 2019-11-28 23:38:38
How to load application settings to NHibernate.Cfg.Configuration object by using System.Configuration.ConfigurationManager from App.config? app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="Northwind" connectionString= "Data Source=(local);Initial Catalog=Northwind;Trusted_Connection=True;> </connectionStrings> </configuration> C# code: string connectionString = System.Configuration.ConfigurationManager .ConnectionStrings["Northwind"].ToString(); NHibernate.Cfg.Configuration nHibernateConfiguration = new NHibernate.Cfg.Configuration();

Open other program's configuration files

拈花ヽ惹草 提交于 2019-11-28 21:37:33
I have a program A , it also have an app.config file where I have added some keys like server address, username and password for connecting to a server. It is a console application. Now I want to make a UI which I have done. In that UI I want to modify the content of app.config of program A . How do I do that? Here is what I tried, I copied the UI (basically an .exe) to program A's directory, where the app.config also resides. Then in the UI, I use the ConfigurationManager class's OpenExeConfiguration method, and passing the program A's filename as an argument. But it throws and exception of

Can ConfigurationManager retain XML comments on Save()?

纵然是瞬间 提交于 2019-11-28 21:11:42
I've written a small utility that allows me to change a simple AppSetting for another application's App.config file, and then save the changes: //save a backup copy first. var cfg = ConfigurationManager.OpenExeConfiguration(pathToExeFile); cfg.SaveAs(cfg.FilePath + "." + DateTime.Now.ToFileTime() + ".bak"); //reopen the original config again and update it. cfg = ConfigurationManager.OpenExeConfiguration(pathToExeFile); var setting = cfg.AppSettings.Settings[keyName]; setting.Value = newValue; //save the changed configuration. cfg.Save(ConfigurationSaveMode.Full); This works well, except for

Why my changes of AppSettings in App.config is not taken into account in run-time? (Console Application)

梦想与她 提交于 2019-11-28 20:49:30
I have a console application which has its own App.config. I need to change some values in section time to time. My problem is, when I execute the exe within the bin/debug folder it gets the relevant appsettings correctly. But when I edit and change values of some key/value pairs and RE-RUN the exe, it still reads the original values. (By RE-RUN I mean running the application on the command promt by calling MyTool.exe) I tried to call ConfigurationManager.RefreshSection("appSettings"); in the begining of my Main method. But did not help. Can you please advise? Thanks But when I edit and change

Does ConfigurationManager.AppSettings[Key] read from the web.config file each time?

你离开我真会死。 提交于 2019-11-28 19:25:10
问题 I'm just wondering how the ConfigurationManager.AppSettings[Key] works? Does it read from the physical file each time I need a key? If so, should I be reading all the app settings of my web.config in a cache and then read from it? Or ASP.NET or IIS loads the web.config file at application_startup and only once. How to verify whether the physical file is accessed by each read? If I change the web.config, IIS restarts my application so can't verify it that way. Thanks, 回答1: It gets cached, on

How to Write to a User.Config file through ConfigurationManager?

我的未来我决定 提交于 2019-11-28 09:15:46
I'm trying to persist user settings to a configuration file using ConfigurationManager. I want to scope these settings to the user only, because application changes can't be saved on Vista/Win 7 without admin privileges. This seems to get me the user's configuration, which appears to be saved here in Win 7 ([Drive]:\Users\[Username]\AppData\Local\[ApplicationName]\[AssemblyName][hash]\[Version\) Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); Whenever I try to save any changes at all to this config I get this exception:

Java configuration framework [closed]

半城伤御伤魂 提交于 2019-11-28 03:01:32
I'm in the process of weeding out all hardcoded values in a Java library and was wondering what framework would be the best (in terms of zero- or close-to-zero configuration) to handle run-time configuration? I would prefer XML-based configuration files, but it's not essential. Please do only reply if you have practical experience with a framework. I'm not looking for examples, but experience... If your hardcoded values are just simple key-value pairs, you should look at java.util.Properties . It's a lot simpler than xml, easier to use, and mind-numbingly trivial to implement. If you are