2011-10-20 3 views
1

web.config에서 연결 문자열의 암호화 기능에 문제가 있습니다.web.config의 암호화 된 연결 문자열에 오류가 발생했습니다.

암호화가 완벽하게 작동합니다! 그러나 암호화가 사용되는 즉시 세션 변수 내용 (세션 변수에 대한 Null 예외)이 손실됩니다.

web.config에서 연결 문자열의 암호화를 비활성화하면 모든 것이 정상으로 돌아갑니다.

#region Constructeur 

static QueryManager() 
{ 
    Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); 
    ConnectionStringsSection section = config.GetSection("connectionStrings") as 
            ConnectionStringsSection; 

    if (section.SectionInformation.IsProtected) 
    { 
    section.SectionInformation.UnprotectSection(); 
    config.Save(ConfigurationSaveMode.Minimal); 
    } 

    if ((myConnectionString = 
     ConfigurationManager.ConnectionStrings["DBConnect"].ConnectionString) == null) 
    { 
    throw new ConfigurationErrorsException("Database server not configured"); 
    } 

    section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); 
    config.Save(ConfigurationSaveMode.Minimal);    
} 

#endregion 

도와 주셔서 감사합니다 만 :

다음은 연결 문자열의 암호화를위한 내 코드입니다!

+0

내 코드는이 웹 사이트를 기반으로합니다. http://msdn.microsoft.com/en-us/library/89211k9b%28v=vs.80%29.aspx –

답변

1

이 오류는 설계 오류로 인해 발생합니다.

  • 먼저, 암호화, 암호화/복호화를 데이터베이스에 대한 요청이 이루어질 때마다 저장하는 것을 방지하기 위해 애플리케이션으로부터 외부로 만들 수있다 : 여기

    솔루션이다.
  • 그런

:

static QueryManager() 
{ 

    Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); 
    ConnectionStringsSection section = config.GetSection("connectionStrings") as 
            ConnectionStringsSection; 

    if (section.SectionInformation.IsProtected) 
    { 
    section.SectionInformation.UnprotectSection(); 
    }    

    myConnectionString = section.ConnectionStrings["DBConnect"].ConnectionString; 

    if (unikSignConnectionString == null) 
    { 
    throw new ConfigurationErrorsException("Database server not configured"); 
    } 
} 

그 방법, 연결 문자열은 메모리에 해독하고 문제를 만들지 않고 사용하고 많은 쓸모 읽기를 방지하고의 Web.config에 기록된다.

관련 문제