[ASP.NET]デザイン時に web.config での定義を使えるようにする
表題の物、おすそ分け。
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 を取ればデザイン時にゴニョゴニョできるとか言わない。
投稿日時 : 2010年1月10日 21:04
Tweet

コメントを追加
# re: [ASP.NET]デザイン時に web.config での定義を使えるようにする 2010年1月10日 21:05 菊池
デザイン時に VirtualPathProvider のふりをするなんかなんて作ってない。