This project has moved and is read-only. For the latest updates, please go here.

Design time access to web.config

Aug 17, 2010 at 11:28 AM


The default method for instantiating a configuration section does not seem to work design-time:

returns a null-reference when accessed design-time.

I've found some resources on this subject, but they only seem to work for classes that inherit


, and therefore any initialization would not be static nor its behaviour singleton anymore. The 'correct' way to do this would be:

public CustomResourceProvider Instance()
	IWebApplication webApp = (IWebApplication)base.Component.Site.GetService(typeof(IWebApplication));
	if (webApp == null) return null;
       	System.Configuration.Configuration config = webApp.OpenWebConfiguration(true);
	return (CustomResourceProvider)config.GetSection("MySectionName");

Where "MySectionName" would refer to the constant as defined by CSD.

Any ideas on this?