GSharper

Friday, 13 April 2007

No more custom section handlers in .NET 2.0

With the framework 2.0 we don't need to write custom section handlers for the web.config file anymore.

Now there are property settings we can use.

Choose the project properties. Then select Settings. There we fill in the key/value pairs. Choose Application for the scope and save.

Now VS has created an app.config file in the project. In the app.config file there's a section group with a section defined in it. There's also an application settings section in it.

Copy section to the section group in the web.config file. Copy the application settings section also to the web.config file.

Delete the app.config file.

Now lets call the settings in your code like this

string mySetting =
Properties.Settings.Default.MySetting;


When you want to get a setting dynamically, use this code



object myDynamicSetting = Properties.Settings.Default.Properties[MyDynamicSettingsKey].DefaultValue;


Greetz,                                                                               G

1 Comments:

  • I also like the Settings-features they put in .NET 2.0 but I'm still supprised to find out how little people know about it. Maybe after your blogpost we'll find less hand-crafted settings-frameworks.

    By Anonymous Anonymous, At 24 April 2007 at 21:12  

Post a Comment

Subscribe to Post Comments [Atom]



<< Home