在Orchard模块中访问模块本地的AppSettings

因为Orchard的模块的路径位于Orchard.Web\Modules\XXX下,不能通过WebConfigurationManager.AppSettings直接访问,可以通过如下方法:

    public class ConfigHelper
{
public static string CurrentAppSettings(string key)
{
return ModuleAppSettings("模块名称", key);
}
private static string ModuleAppSettings(string module, string key)
{
Configuration config
= WebConfigurationManager.OpenWebConfiguration(string.Concat("~/Modules/", module));

KeyValueConfigurationCollection appSettings
= config.AppSettings.Settings;WebConfigurationManager.AppSettings

return appSettings[key].Value;
}
}

参考:http://msdn.microsoft.com/en-us/library/ms151456.aspx

posted @ 2011-08-18 11:57  chenjunbiao  阅读(298)  评论(0编辑  收藏  举报