表題の物、おすそ分け。
using System.Configuration;
using System.Web.UI;
using System.Web.UI.Design;
namespace System.Web.UI
{
public static class ControlExtender
{
public ConfigurationSection GetConfigurationSection( this Control control, string sectionName )
{
if( control.Site.DesignMode ) {
var webApp = control.Site.GetService( typeof( IWebApplication) );
return webApp.OpenWebConfiguration( true ).GetSection( sectionName );
}
// デザインモードでないから通常の ConfigurationManager を使う
return (ConfigurationSection)ConfigurationManager.GetSection( sectionName );
}
}
}
IWebApplication の RootProjectItem からIProjectItem をゴニョゴニョすると開発環境で認識できてるはずのものを列挙できるとか、固定の場所にある事が前提なら GetProjectItemFromUrl してPhysinalPath を取ればデザイン時にゴニョゴニョできるとか言わない。