【发布时间】:2015-01-28 16:57:51
【问题描述】:
我正在尝试在自动部署后加密 web.config 文件。
根据链接:https://blogs.iis.net/msdeploy/archive/2013/07/09/webdeploy-3-5-rtw.aspx
我正在使用以下命令:
msdeploy.exe –verb:sync –source:iisapp=”sourceTestSite” –dest:iisapp=”destinationTestSite” –EnableRule:EncryptWebConfig
但后来我收到错误:
错误代码:ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG
我不想先加密然后部署。我正在考虑运行部署脚本,部署后它应该使用 MSDEploy 命令自动加密。
我尝试了以下线程但没有得到任何帮助:
Failed to encrypt destination web.config when using MS build plugin in Jenkins
我还想将我的秘密文件保存在单独的位置,但我发现加密过程不适用于那个
How to encrypt a file linked to a web.config
这次我尝试在远程服务器上运行命令以使用以下代码加密 web.config 文件。我在我的机器上运行下面的代码并尝试加密 myRemoteServer 上的 web.config 文件。
$currentDirectory = (Get-Location)
$user = "domain1\username1"
$section = "appSettings"
$app= "/MyWeb"
$version="v4.0.30319"
$computername ="myRemoteServer"
$pwd = ConvertTo-SecureString -String "mysecret@11" -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$pwd
$encryptcmd1= Set-Location "C:\windows\Microsoft.Net\Framework\$version"
$encryptCmd2 = ".\aspnet_regiis.exe -pe ""appSettings"" -app ""/MyWeb"""
$encryptCmd = "$encryptcmd1 $encryptcmd2"
try
{
invoke-command -ComputerName $computername -Credential $credential -ScriptBlock {$encryptCmd}
}
catch
{
Log-Message $_
}
Set-Location $currentDirectory
它不会抛出任何异常。但是它不工作并且不加密该服务器上的 web.config 文件。 我想知道这里哪里/哪里出了问题。
【问题讨论】:
-
目前我正在做下面的事情来使用powershell进行加密
标签: encryption msdeploy