/// <summary> /// 获取系统数据 /// </summary> /// <param name="key"></param> /// <remarks>需在网站根目录的App_Data存放指定格式的SysDataConfig.xml文件</remarks> /// <returns></returns> private static T GetSysData <T>(string key) { try { object obj = HttpRuntimeCache.Get(_sysDataConfigKey); XElement xe = null; if (obj == null) { xe = XElement.Load(UrlHelper.MapPath("~/App_Data/SysDataConfig.xml")); //缓存一天 HttpRuntimeCache.SetCache(_sysDataConfigKey, xe, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration); } else { try { xe = (XElement)obj; } catch { } } XElement elNodeIndexName = (from nodeIndexName in xe.Elements("item") where nodeIndexName.Attribute("key").Value == key select nodeIndexName).ElementAt(0); string val = elNodeIndexName.Attribute("value").Value; return(Common.ConvertValue <T>(val)); } catch (Exception e) { throw new Exception(string.Format("系统数据配置出现错误,可能原因:在网站根目录App_Data文件夹下找不到SysDataConfig.xml文件,或文件内容格式错误。详细信息如下:{0}", e.Message), e); } }
/// <summary> /// 得到AppSettings中的配置字符串信息 /// </summary> /// <param name="key"></param> /// <returns></returns> private static string GetConfigString(string key) { string CacheKey = "AppSettings-" + key; object objModel = HttpRuntimeCache.Get(CacheKey); if (objModel == null) { try { objModel = ConfigurationManager.AppSettings[key]; if (objModel != null) { HttpRuntimeCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(180), TimeSpan.Zero); } } catch { } } return(objModel.ToString()); }