0

DataProtectionConfigurationProvider을 사용하여 로컬에서 정상적으로 작동하는 web config의 연결 문자열을 암호화했습니다.DataProtectionConfigurationProvider를 사용하는 웹 구성 암호화가 제품에서 작동하지 않습니다.

하지만 제작에 코드를 업로드하면 웹 설정이 암호화되지 않습니다.

가 나는 다음 코드를 사용하고 있습니다 :

Configuration config = 
       WebConfigurationManager.OpenWebConfiguration("/"); 
      // Let's work with the <connectionStrings> section 
      ConfigurationSection connectionStrings = config.GetSection("connectionStrings"); 
      if (connectionStrings != null) 
      { 

       // Only encrypt the section if it is not already protected 
       if (!connectionStrings.SectionInformation.IsProtected) 
       { 
        // Encrypt the <connectionStrings> section using the 
        // DataProtectionConfigurationProvider provider 
        connectionStrings.SectionInformation.ProtectSection(
         "DataProtectionConfigurationProvider"); 
        config.Save(); 
       } 
      } 

나는 로그를 넣어 코드를 추적하고 것을 발견 조건이 작동하지 않습니다 connectionStrings.SectionInformation.IsProtected!.

도움이 될 것입니다!

답변

0

WebConfigurationManager.OpenWebConfiguration ("/")에 "/"경로가 있기 때문에 문제가 발생했습니다. 내 응용 프로그램은 가상 디렉터리 내에 호스팅됩니다.

Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); 
: 코드 아래 사용

문제를 해결