zoukankan      html  css  js  c++  java
  • 操作config文件

    Configuration objConfig = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.StartupPath + @"\TestConfig.exe");

    //需要有TestConfig.exe文件
                    ConnectionStringsSection objAppsettings = null;
                    objAppsettings = (ConnectionStringsSection)objConfig.GetSection("connectionStrings");
                    foreach (ConnectionStringSettings s in objAppsettings.ConnectionStrings)
                    {
                        Console.WriteLine(s.Name);
                        if (s.Name == "ConnectionString")
                        {
                            string ss;
                            if (s.LockItem == false)
                            {
                                ss = s.ConnectionString;
                                s.ConnectionString += " encrypt";
                                s.LockItem = true;
                                objConfig.Save(ConfigurationSaveMode.Modified);
                            }
                            else
                            {
                                ss = s.ConnectionString;

                            }
                            Console.WriteLine(ss);
                        }
                    }
                    Console.ReadKey();

                    if (!objAppsettings.SectionInformation.IsProtected)
                    {
                        objAppsettings.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
                        objAppsettings.SectionInformation.ForceSave = true;
                        objConfig.Save(ConfigurationSaveMode.Modified);
                    }
                    else
                    {
                        objAppsettings.SectionInformation.UnprotectSection();
                        objAppsettings.SectionInformation.ForceSave = true;
                        objConfig.Save(ConfigurationSaveMode.Modified);
                    }

  • 相关阅读:
    记录一次servlet页面无法跳转的血的教训
    1862-your password has expired. To log in you must change it using a client that supports expired passwords.问题解决
    Error starting static Resources java.lang.IllegalArgumentException: Document base D:eclipse*wtpwebapps* does not exist or is not a readable directory问题的解决
    MapReduce Shuffle过程的简单理解
    MapReduce实验03——排序
    zachman架构
    大型高并发与高可用缓存架构总结2
    金蝶SOA案例分析
    感悟:菜鸟弹性调度系统的架构设计
    大型高并发与高可用缓存架构总结
  • 原文地址:https://www.cnblogs.com/djian/p/1922698.html
Copyright © 2011-2022 走看看