远程部署(MVC和TeamCity)并加密Web.config

时间:2013-05-28 09:46:07

标签: asp.net-mvc web-config teamcity

好的,我愿意接受以下建议:

  • 我正在使用 TeamCity MSBuild 将MVC网站部署到远程服务器。
  • 我还希望在部署时加密我的Web.Config。
  • 我一直在推荐行上使用 aspnet_regiis.exe 来在本地执行此操作,但我不确定如何在远程部署中执行此操作。

我目前使用的命令是:

aspnet_regiis.exe -pe "connectionStrings" -app "/" -site "my.IIS.site.name.here"

任何帮助非常感谢...是否有TeamCity的“远程命令行”工具(有一个本地命令行选项),或者它应该是 msproj xml 文件的一部分呢?还是完全有另一种方法?

1 个答案:

答案 0 :(得分:1)

我在Application_Start中添加了一个函数:

public static void EncryptConfig(string path, string configSection)
{
    Configuration config = WebConfigurationManager.OpenWebConfiguration(path);
    ConfigurationSection section = config.GetSection(configSection);

    if (section == null || section.SectionInformation.IsProtected) return;

    section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
    config.Save();
}

路径变量可以用Request.AbsolutePath填充,configSection可以是“connectionStrings”。像魅力一样工作!

相关问题