0
내 Web.config의에서 연결 문자열을 암호화하는 다음과 같은 방법을 사용하고
에서 실행 실패 : 나는이 메소드에 대한 호출을 배치 암호화 연결 문자열 때 서버
public static void EncryptConnectionString()
{
var section = GetConfigSection();
if (section.SectionInformation.IsProtected) return;
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
section.SectionInformation.ForceSave = true;
section.CurrentConfiguration.Save();
}
private static ConnectionStringsSection GetConfigSection()
{
var config = WebConfigurationManager.OpenWebConfiguration("~");
var section = config.GetSection("connectionStrings");
if (section.ElementInformation.IsLocked || section.SectionInformation.IsLocked) return null;
return section as ConnectionStringsSection;
}
- Global.asax의
Application_Start()
메서드 - 로컬에서 실행 중일 때 메서드가 작동하면 연결 문자열이 암호화 된 것을 볼 수 있습니다.
- 서버에서 실행할 때이 방법은 작동하지 않습니다. 앱을 실행하면 서버의 연결 문자열에있는 web.config가 암호화되지 않은 상태로 유지됩니다.
- 수동으로 다른 곳에서 메서드를 호출하면 제대로 작동하는 것처럼 보입니다. 앱의 HomeController에서 호출하면 연결 문자열이 암호화 된 것을 볼 수 있습니다.
- 등록 된 번들이 사용되는 것을 볼 수 있기 때문에 Global.asax의
Application_Start()
에있는 다른 방법이 작동하는 것처럼 보입니다.
그렇다면 Application_Start()
에서 호출 할 때 web.config를 편집하는이 메서드를 호출하지 않는 것이 어떻습니까?