.Net tools to use: Nini





An uncommonly powerful .NET configuration library.
Use this for reading web.config (instead of .Net built-in System.Configuration…) and any other .ini-file or .xml-file containing configuration.


2 lines to read (usually called at page_load or similar).

Sample usage:

[sourcecode language=”csharp”]
// Set up our config source as web.config or app.config
internal static IConfigSource ConfigRoot =
new Nini.Config.DotNetConfigSource(DotNetConfigSource.GetFullConfigPath());
// Create a config object for section “appSettings”
internal static Nini.Config.IConfig Config = cs.Configs[“appSettings”];

// Read some keys from appSettings section
string mystring = Config.GetString(“SomeKey”, “DefaultValue”);
int myint = Config.GetInt(“SomeKey2”, 10);
int mybool = Config.GetInt(“SomeKey3”, true);


  • Automatic type conversion (GetString, GetInt, GetBool, etc).
  • Configuration can be both read and written to.
  • Can read/write to web.config, .ini-files, .xml-files (with hierarcy) and SQL-database.
  • Changing configuration source is easily done by changing a single line. For example moving config from web.config to SQL at a later point in the project is just chaging a single line.
  • Several files can be read and merged into the same instance, so you can split config into many files. So you can read parts from web.config and parts from SQL.
  • This means that configuration can be moved from web.config to a SQL-table at any point with almost no effort.
    Storing config in SQL allows you to keep the files the same configuration between prod and test.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: