Getting Settings from web.config at design time

Skip Navigation LinksIrocon > Blog > 2005 > November, 2005 > November 14, 2005 > Getting Settings from web.config at design time

Getting Settings from web.config at design time

Elion at the Asp.net forums provides a very neat way of pulling settings from web.config at design time.



To get access to configuration at design time, use the IWebApplication service. From your control's designer, do something like this:

IWebApplication webApp = (IWebApplication)GetService(typeof(IWebApplication));
if (webApp != null) {
Configuration config = webApp.OpenWebConfiguration(true);
string appSettingsValue = config.AppSettings.Settings["SomeKey"].Value;
}

This is basically what SqlDataSource does in a few places, though it does it with the ConnectionStrings section instead of AppSettings.

Thanks,
Eilon

Last Updated:Thursday, September 02, 2010By:alferoSource#

Would you like to comment?

Sign in with your OpenID. If you do not know what OpenID is, find out.