Runtime web.configapp.config editing

xiaoxiao2021-03-06  59

Web.config configuration files and app.config project item files, which get converted to "ExecutableName.exe.config" at build time, both support the convenient appSettings section with its own read method in the System.Configuration.ConfigurationSettngs class. The appSettings Section Stores Element Name / Value Pairs in The Format:

You can store as many of these elements as you want, read them out at runtime, and use the values ​​in the application. If you have an item that contains multiple values ​​and you would like to keep them together, you can store THEM AS A SINGLE STRING, DELIMITED WITH A PIPE | Or Other Symbol, Read The String.Split () Method to Parse Them Into A Useable String Array.

I offten ot my appsetting value INTO A NameValueCollection At Runtime, Which Provides One-Shot Acess To The Entire Collection In Memory:

NameValueCollection mySettings = system.configuration.conmfigurationSettings.appsettings; string connStr = MySettings ["connString"];

But what about being able to change, add, and save appSettings items while that app is running in response to user input or other actions, instead of just reading them out? Nada, Zippo, Efes! You have to open the config file manually and add them by "hand". Well that kinda stinks, do not you think? So here's my take on a convenient little class that allows you to either modify, add or delete any appSettings element, in either your Executable, Console or ASP. NET web application at runtime, on the fly. Bear in mind of course, that if you modify a web.config on a running ASP.NET app, the ASP.NET worker process will recycle. Users currently using your app are not exactly Guaranteed to Have A Fun Experience When this happens ... New Articles & TIPS

SQL Server Reporting Services -. Lessons LearnedDr Dotnetsky's Cool .NET Tips and Tricks # 18.NET Compact Framework Save Signature To FileCompressed Ink for Tablet PC and Windows XPWebService Enabling SQL Server 2005 Methods

HOWTO: Register An Assembly in the GA.NET Framework 1.1 - IssuesCircular References / Memory Leaks / Other BaddiesrsRsources Section Now Open for Testing! .NET Compact Framework App.config Workaround