企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 文件路径 ``` ConfigHelper.cs ``` ## 1、得到web.config AppSetting 下key值 ``` /// <summary> /// 得到web.config AppSetting 下key值 <appSettings><add key="useEncrypt" value="false"/></appSettings> /// </summary> /// <param name="key">关键字</param> /// <returns>返回值</returns> public static string GetValue(string key) { try { return ConfigurationManager.AppSettings[key]; } catch (Exception ex) { throw new System.Exception(ex.Message); } } ``` ## 用法 ``` var useValidateCode = ConfigHelper.GetValue("showValidateCode"); ``` ## 2、设置web.config AppSetting 下key值 ``` /// <summary> /// 设置应用程序配置节点,如果已经存在此节点,则会修改该节点的值,否则添加此节点 /// </summary> /// <param name="key">节点名称</param> /// <param name="value">节点值</param> public static void SetAppSetting(string key, string value) { Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); AppSettingsSection app = config.AppSettings; app.Settings[key].Value =value; config.Save(ConfigurationSaveMode.Modified); } ``` ## 用法 ``` ConfigHelper.SetAppSetting("website", "http://www.ynicp1.com");//注意节点website需要手动添加 因为安全的原因自动添加节点会报错 ``` ## 效果 ``` <appSettings> <add key="dbname" value="bpm" /> <add key="host" value="" /> <add key="useEncrypt" value="false" /> <add key="systemName" value="精准扶贫" /> <add key="copyRight" value="精准扶贫" /> <add key="website" value="http://www.ynicp1.com" /> <add key="showValidateCode" value="false" /> <add key="CombresSectionName" value="combres" /> </appSettings> ```