Its an odd feeling when you discover something in your own product, you didn't quite knew existed!
Theres a little known attribute called configSource, that can be specified on a section which allows the definition of the section to live in another actual file. Well, actually I had a vague recollection of it, from past work around IIS7 and config, and went hunting for it this morning in the context of discussing a new feature that is dependent on some new configuration entries. This is especially relevant given some of the complaints around the use of configuration in various ASP.NET Ajax features.
Here's an example scenario... the profile feature allows me to specify a bunch of named properties that should be managed per-user, along with type information and other metadata. This information currently goes within the <profile> section within <system.web> in web.config. This always struck me as odd. The profile settings are first and foremost defining database schema, application logic (by virtue of generating a strongly-typed class), and only then is it about configuration in a classic sense. I've always thought it would be better if this information was in a separate .profile kind of file. Well, with configSource, you can do just that... almost!
For example, here's what I can put into my web.config:
...
<system.web>
...
<profile configSource="profile.config" />
...
</system.web>
...
Once I've done that, I can now add a profile.config file into my web site as follows:
<profile>
<properties>
<add name="Name" type="String" />
<add name="Age" type="Int32" />
</properties>
</profile>
Everything continues to work as before. Essentially I've cut out the actual profile section from web.config and moved it into a separate file, which might help manage config a bit better, simply by splitting it out, as well as perhaps make me a bit happier that profile information isn't mixed with configuration! Note that you should probably still name these additional files as .config, so they aren't served out. The MSDN documentation for this property has an example that uses a separate .xml file - bad choice.
This is essentially feature that provides include semantics. However, looking at this makes me wish we had a feature that provided merge, so I could for example, define the profile providers in web.config, and just the properties in profile.config. Configuration is already quite complex with merge happening across different levels in the hierarchy (machine, site, app, folder, file), and this would be a merge at a single level, so its hard to say whether this will happen any time soon. If it did exist, the merge-like feature would have allowed us to actually define an Ajax.config file which could be added to a site to Atlas-enable the site for example, rather than having to merge config settings all over the place in the single web.config file. For example, to enable ASP.NET Ajax, there is a new system.web.extensions section that could go into a separate file. In addition there are couple of required entries in the httpModules and httpHandlers sections. No doubt, this limits the feature a bit, but still useful in some limited scenarios.
Posted on Wednesday, 4/25/2007 @ 11:37 AM
| #
ASP.NET