当加密的连接字符串保存在外部配置文件中并由asp.net应用程序的web.config的connectionStrings部分中的configSource属性指定时,如何在C#代码中读取加密的连接字符串?
外部配置文件应该只有connectionStrings节点,但是当它被加密时,configDataProvider节点也应该出现在同一个文件中 . 因此它不能在configSource属性中使用 .
我有加密的连接字符串,并希望在外部配置文件中 . 怎么办呢?
谢谢你的任何指示 .
在你的app.config中:
<configuration> <connectionStrings configSource="foo.config" /> ... </configuration>
并在你的 foo.config :
foo.config
<connectionStrings configProtectionProvider="DataProtectionConfigurationProvider"> <EncryptedData> <CipherData> <CipherValue> AQAAANCMnd8BFdE.... </CipherValue> </CipherData> </EncryptedData> </connectionStrings>
在你的代码中:
ConfigurationManager.ConnectionStrings["someKey"]
1 回答
在你的app.config中:
并在你的
foo.config
:在你的代码中: