我能够使这个工作的方式是,前往每台机器并使用正确的连接字符串加密web.config文件,然后将新加密的连接字符串部分复制到相应的web.cong转换中。虽然非常麻烦,但它能够正常运行。
根据您的需求和开发团队对服务器的不同访问方式,有几种不同的处理方法。
使用aspnet_regiis.exe创建您的web.config并加密appsettings和connectionstrings。然后在每个环境的变换中(例如web.release.config)使用以下值:
<appSettings configProtectionProvider="ProviderName" xdt:Transform="Replace">
<EncryptedData>.....</EncryptedData
</appSettings>
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
才能使用EncryptedData,否则Visual Studio将报错:Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened.
。添加命名空间后,由于某种原因,Visual Studio忽略了xdt:Transform="Replace"
。 - Neurion ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
configMap.ExeConfigFilename = modulePath + "Web.Release.config";
System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
System.Configuration.ConfigurationSection section = config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
config.Save();
}
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"
中。你有什么想法吗? - Sam我们的设置是这样的...
项目 web.config 中包含所有常见的开发内容,包括任何在生产环境中被视为私有的开发应用程序设置。在我们的情况下,这些设置被检入并不重要,因为它们只是供我们内部使用。通过发布,转换会删除所有这些信息。
我们的构建服务器管理“发布”和转换。所以当我们为特定的配置进行构建时,该转换会运行并删除所有敏感信息。
下一步是构建将 web.config
重命名为 web.config.default
。这允许我们提供一个配置文件,其中包含所有默认设置,但没有敏感数据,这些设置是针对该构建的特定设置。
在第一次部署时,由部署人员将 web.config.default
重命名为 web.config
并填写敏感信息。从那里开始,他们可以选择是否加密信息。
每个后续部署都不会覆盖当前的 web.config
- 它只会添加默认值 - 由进行部署的人员添加或删除任何新/弃用的配置元素。
此外,这里的手动步骤也可以使用某种安装程序自动化...
Then you can do something like:
</connectionStrings>
<appSettings file="relative\path\to\AppSettingsSecrets.config">
</appSettings>
<system.web>
关于connectionStrings
您可以使用configSource属性替换整个markup。与合并markup的file属性不同,configSource属性会替换markup。
部署期间
您可以前往Azure管理门户手动设置它们,在WebApps > 您的WebApp > 所有设置 > 应用程序设置中进行设置。
请查看this链接以获取更多参考资料。
aspnet_regiis
方式加密web.release.config
文件。 - Brian Diggs