private bool SaveConfig(out string errorMsg) { bool result; try { Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(base.Request.ApplicationPath); configuration.AppSettings.Settings.Remove("Installer"); using (System.Security.Cryptography.RijndaelManaged cryptographer = this.GetCryptographer()) { configuration.AppSettings.Settings["IV"].Value = System.Convert.ToBase64String(cryptographer.IV); configuration.AppSettings.Settings["Key"].Value = System.Convert.ToBase64String(cryptographer.Key); } System.Web.Configuration.MachineKeySection machineKeySection = (System.Web.Configuration.MachineKeySection)configuration.GetSection("system.web/machineKey"); machineKeySection.ValidationKey = Install.CreateKey(20); machineKeySection.DecryptionKey = Install.CreateKey(24); machineKeySection.Validation = System.Web.Configuration.MachineKeyValidation.SHA1; machineKeySection.Decryption = "3DES"; configuration.ConnectionStrings.ConnectionStrings["EcShopSqlServer"].ConnectionString = this.GetConnectionString(); configuration.ConnectionStrings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); configuration.Save(); errorMsg = null; result = true; } catch (System.Exception ex) { errorMsg = ex.Message; result = false; } return(result); }
private bool SaveSiteSettings(out string errorMsg) { errorMsg = null; if (this.siteName.Length > 30 || this.siteDescription.Length > 30) { errorMsg = "网店名称和简单介绍的长度不能超过30个字符"; return(false); } bool result; try { string filename = base.Request.MapPath(Globals.ApplicationPath + "/config/SiteSettings.config"); System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument(); SiteSettings siteSettings = new SiteSettings(base.Request.Url.Host); xmlDocument.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + System.Environment.NewLine + "<Settings></Settings>"); siteSettings.AliOHServerUrl = "https://openapi.alipay.com/gateway.do"; siteSettings.SiteName = this.siteName; siteSettings.SiteDescription = this.siteDescription; siteSettings.CheckCode = Install.CreateKey(20); siteSettings.WriteToXml(xmlDocument); siteSettings.VipCardBG = "/Storage/master/Vipcard/vipbg.png"; xmlDocument.Save(filename); result = true; } catch (System.Exception ex) { errorMsg = ex.Message; result = false; } return(result); }