Best way to store the site configuration in the db

Coordinator
Jan 24, 2011 at 1:07 PM

Which would be the best way to store the site configuration (Site.config file) in the db...?

(Without coding again all SiteConfiguration elements, and taking in account a n-tiers design) 

I found a question in stackoverflow that proposed a hack: http://www.wrox.com/WileyCDA/Section/Redirecting-Configuration-with-a-Custom-Provider.id-291932.html

But is there a better way? 

Coordinator
Jan 24, 2011 at 1:32 PM

What would be the advantages of storing the config in the DB?

Coordinator
Jan 24, 2011 at 1:37 PM

I forgot to explain this above...

Its for the forum administrator to change settings from the admin dashboard.

It is possible to overwrite a configuration file using default .net configuration but you need write acl permissions on the file. Assign permissions on a file does bring some complexity in the installation...

Coordinator
Jan 25, 2011 at 3:29 AM

I read the article on wrox. Though it seems like a clever solution I still don't get the need to use the ProtectedConfigurationProvider class as the article explains. Is it for config files that need to be stored as encrypted or for any config file? :-/ We could always modify the classes not to inherit from the ConfigurationElement Class and because the class uses properties for encapsulation, we could write the backend code to get the values from the database. We would be violating the Open Closed Principle of course :-) hehe I don't know maybe it's a crazy idea of mine. Also, we can store the config as a XML datatype in SQL Server (I don't know if it could work with MySQL) and do some hackery-magic to read the config sections. It's something we can research further. Here's a link:

http://stackoverflow.com/questions/4339167/how-to-read-a-configuration-section-from-xml-in-a-database

Coordinator
Jan 25, 2011 at 9:07 AM

On the article on wrox, it uses the ProtectedConfigurationProvider (used to encrypt and decrypt the configuration) in order to get the configuration from the db. It is not what ProtectedConfigurationProvider is meant for but it works...

Avoid inheriting directly from ConfigurationElement it's a good start...

Nice discussion at stackoverflow, I offered some reputation to the person that answers it!

Coordinator
Jan 26, 2011 at 3:57 AM

It would have been nice to use SQL Server's XML datatype to store the config. However, After some research I found out that apparently MySQL does not support such a datatype. In the meantime we can just verify if the user have write permissions on the XML config files and display that status on the initial installation status page. What do you think?

Coordinator
Jan 31, 2011 at 1:36 PM
Edited Jan 31, 2011 at 1:37 PM

There has been updates on this matter on the SO topic I posted above. Very interesting answers by the way.