Не удается зашифровать строки подключения в winforms, но работает в сети? Ммм Можете ли вы помочь - PullRequest
1 голос
/ 03 декабря 2009

Не могу понять, почему это работает в сети (меняется на WebConfigManager), а не в winapp. Когда я смотрю на файл конфигурации, он все еще не зашифрован !! Вы можете помочь?

 EncryptionUtility.ProtectSection("connectionStrings", "DataProtectionConfigurationProvider");

public class EncryptionUtility
    {
        public static void ProtectSection(string sectionName,string provider)
        {
            var config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);

            var section = config.GetSection(sectionName);

            if (section == null || section.SectionInformation.IsProtected) return;
            section.SectionInformation.ProtectSection(provider);
            config.Save();
        }

        public  static void UnProtectSection(string sectionName)
        {
            var config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);

            var section = config.GetSection(sectionName);

            if (section == null || !section.SectionInformation.IsProtected) return;
            section.SectionInformation.UnprotectSection();
            config.Save();
        }
    }

1 Ответ

0 голосов
/ 03 декабря 2009

В winforms у вас есть 3 файла конфигурации: один в проекте, в каталоге отладки и один в каталоге релиза. Вы уверены, что пытаетесь зашифровать правильный?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...