ASP.NET custom config entries / ConfigurationSections + business logic validation?

i've got some custom config entries in my .config files. All loads/works fine. I was wondering if there's a proper way to check the data that has been provided -- adding some business logic. For example...

<logFileSettings>
    <logFile fileName="foo.log" uniqueName="log1">
        <alerts>
             -= snip =-
        </alerts>
    </logFile>
    <logFile fileName="bar.log" uniqueName="log2">
        <alerts>
             -= snip =-
        </alerts>
    </logFile>
</logFileSettings>

Now, i want to make sure the uniqueName for each custom sections are unique. Do i need to do this manually outside of my custom class which impliments ConfigurationSection or can i do it in there? (eg. sorta like a delegate to after it's read the config file or something?)

Answers


This sounds like a job for the consumer of the data, not the data store (in this case, the web.config).

It is possible to read/write the web.config from code, but this is almost always a very bad idea (for one thing, writing will always restart the web application, and even reading will too sometimes). I understand that this is not what you are asking, but I wanted to point it out because I am horrified by the number of people who read/write web and app.config files with reckless abandon.

To your original question of whether or not there is an event raised when the file is parsed, I did some reading and couldn't find anything. However, you probably could modify the Visual Studio XML schema for the web.config, and at least you would have a design time error.

Or more importantly, I would suggest moving the validation logic to the consumer of the data (looks like a logging class).


Need Your Help

Making my computer prompt me with a predeterminedquestion whenever I open firefox

java osx firefox

I'm inspired by reading this from John Conway's wikipedia page:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.