Typed configuration data in a separate config file in ASP.Net 4.0?
- I have an asp.net 4.0 web application.
I need extensive configur开发者_如何转开发ation data for this web application, that is strongly typed and the structure of this configuration data is going to be fairly complex (cannot do with key-value pairs). In the past I remember having done this in .Net 2.0 but cannot figure out how I will do it in .Net 4.0. The class and config mapping is like shown below (really simplified for the purpose of illustration only):
class SettingsClass { int count; string name; decimal amount; } <SettingsClass> <count>2</count> <name>Moiz</name> <decimal>10.66</decimal> </SettingsClass>
- I need this configuration in a separate file (other than the web.config).
- I don't think I would have to write explicit serialization/deserialization code.
Does .Net 4.0 configuration classes provide this kind of built in facility?
Would I need to use Enterprise Library 5.0 to get this done?
You can introduce strongly typed sections in configuration files with custom configuration handlers.
If you need these configurations in a separate file you can use OpenMappedExeConfiguration to load additional configuration files.
You can use both practices in .NET 2.0 and 4.0.
精彩评论