源码地址: https://gitee.com/zhang_jianli

app.config ConfigSection 保护

 public void ProtectSection(string sectionName)
       {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ConfigurationSection protectedSection= config.GetSection(sectionName);

        // Encrypts when possible
        if ((protectedSection!=null) && (!protectedSection.IsReadOnly()) && (! protectedSection.SectionInformation.IsProtected)
        && (!protectedSection.SectionInformation.IsLocked) && (protectedSection.SectionInformation.IsDeclared))
        {
            // Protect (encrypt)the section.
            protectedSection.SectionInformation.ProtectSection(null);
           // ' Save the encrypted section.
            protectedSection.SectionInformation.ForceSave =true;
            config.Save(ConfigurationSaveMode.Full);
        }
        
       }

posted on 2011-10-09 12:11  天涯  阅读(328)  评论(0编辑  收藏  举报

导航

源码地址: https://gitee.com/zhang_jianli