zoukankan      html  css  js  c++  java
  • 在web应用程序中在网页中对Web.config文件进行数据连接配置

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Configuration;
     4 using System.Web.Configuration;
     5 using System.Text;
     6 using System.IO;
     7 
     8     /// <summary> 
     9 /// SystemConfig 的摘要说明 
    10 /// </summary> 
    11 public static class SystemConfig
    12 {
    13     private static Configuration ConfigFile;
    14     private static KeyValueConfigurationCollection SysConfig;
    15 
    16     static SystemConfig()
    17     {
    18         ConfigFile = WebConfigurationManager.OpenWebConfiguration("/");
    19         SysConfig = ConfigFile.AppSettings.Settings;
    20     }
    21 
    22     public static void setValue(string configfilepath, string key, string value) 
    23     {
    24         ExeConfigurationFileMap map = new ExeConfigurationFileMap();
    25         map.ExeConfigFilename = configfilepath;
    26         ConfigFile = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
    27         SysConfig = ConfigFile.AppSettings.Settings;
    28 
    29         KeyValueConfigurationElement el = SysConfig[key];
    30         if (el == null)
    31         {
    32             SysConfig.Add(key, value);
    33         }
    34         else
    35         {
    36             el.Value = value;
    37         }
    38 
    39         //同步更新
    40         ConfigFile.Save();
    41 
    42     }
    43 
    44 }
  • 相关阅读:
    C++虚继承内存布局
    编译OpenJDK记录
    Node.js + Express 调研
    软件工程开发工具
    Servlets & JSP & JavaBean 参考资料
    Eclipse AST 相关资料
    Git & github 最常用操作笔记
    Java入门学习资料整理
    从变量的类型转换看C语言的思维模式
    数学地图(1)
  • 原文地址:https://www.cnblogs.com/ToFlying/p/3183506.html
Copyright © 2011-2022 走看看