2008-10-02 5 views
6

콘솔 응용 프로그램의 App.config 파일에서 appSettingsconnectionStrings 섹션을 암호화하려고합니다. 어떤 이유로 든 section.SectionInformation.IsProtected은 항상 true를 반환합니다.App.config 파일의 섹션 보호 콘솔 응용 프로그램

static void Main(string[] args) 
{ 
    EncryptSection("connectionStrings", "DataProtectionConfigurationProvider"); 
} 

private static void EncryptSection(string sectionName, string providerName) 
{ 
    string assemblyPath = Assembly.GetExecutingAssembly().Location; 
    Configuration config = ConfigurationManager.OpenExeConfiguration(assemblyPath); 

    ConfigurationSection section = config.GetSection(sectionName); 

    if (section != null && !section.SectionInformation.IsProtected) 
    { 
     section.SectionInformation.ProtectSection(providerName); 
     config.Save(); 
    } 
} 

왜 항상 true를 반환하는지 잘 모르겠습니다.

답변

2

코드가 현재 응용 프로그램 구성을 엽니 다. 시도해 볼 수 있습니다 :

관련 문제