publicvoid SaveSiteSettings() { // 原来的:从Cache中获取站点设置信息数据集(好像是个Bug,因为每次更新数据是更新的HttpContext.Current.Items中的) //SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Cache["SiteSettings"]; // 修改后的 SiteConfiguration siteSettings = (SiteConfiguration) HttpContext.Current.Items["SiteSettings"]; // 如果Cache中没有,则重新构建 if(siteSettings ==null) { // If SaveSiteSettings() is called once, the cache is cleared. If it is // then called again before Global.Application_BeginRequest is called, // which reloads the cache, the siteSettings object will be Null // (这一句不知翻译的对不对,好像很重要)如果SaveSiteSettings()被调用过一次后,Cache就回被清除。如果它再一次被调用在Global.Application_BeginRequest前siteSettings为null则重新写Cache siteSettings = GetSiteSettings(); } string configFile = HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["configFile"]); // Object is evicted from the Cache here. // 将变更后的数据集写入到Xml文件 siteSettings.WriteXml(configFile); }