net msdeploylewebconfigencryptrule无法对web.config进行加密

时间:2021-11-14 20:24:27

I have added <MSDeployEnableWebConfigEncryptRule>true</MSDeployEnableWebConfigEncryptRule> to .pubxml file in order to encrypt web config file. However, when publishing, i got the following error. I do not know whether there is extra setting needed in the web.config file other than inserting <MSDeployEnableWebConfigEncryptRule>true</MSDeployEnableWebConfigEncryptRule> in .pubxml

我已经将< msdeploylewebconfigencryptrule >true添加到.pubxml文件中,以便对web配置文件进行加密。但是,在发布时,我得到了以下错误。我不知道网站是否需要额外设置。除了在.pubxml中插入< msdeploylewebconfigencryptrule >true 之外的配置文件

Error: Web deployment task failed.(Fail to encrypt destination web.config. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG.)

错误:Web部署任务失败。(未能加密目标web.config。了解更多:http://go.microsoft.com/fwlink/?LinkId=221672 ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG)。

Note: #ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG does not appears anywhere on the given link.

注意:#ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG不会出现在给定链接的任何地方。

How could i resolve this error? (note: i do not wish to pre-encrypt the web.config file locally before publishing it)

我如何解决这个错误?(注:我不希望预先加密网页。在发布之前本地配置文件)

2 个解决方案

#1


2  

The problem seem to be that MSDeployEnableWebConfigEncryptRule doesn't work with MVC project that have multiple web.config files. Typically MVC project has Views/Web.Config file. This seems like a bug with MSDeploy.
My Workaround is to have a post deployment powershell script to perform same command on the destination server. See http://www.iis.net/learn/publish/using-web-deploy/web-deploy-powershell-cmdlets

问题似乎是,MSDeployEnableWebConfigEncryptRule不使用具有多个web的MVC项目。配置文件。典型的MVC项目有视图/Web。配置文件。这似乎是一个带有MSDeploy的错误。我的解决方案是使用后部署powershell脚本在目标服务器上执行相同的命令。参见http://www.iis.net/learn/publish/using-web-deploy/web-deploy-powershell-cmdlets

Powershell Script Sample:

Powershell脚本示例:

    Add-PSSnapin WDeploySnapin3.0
    $cmd = '%windir%\Microsoft.NET\Framework\v4.0.30319\ASPNET_REGIIS.exe -{0} {1} "{2}"' -f 'pef', 'connectionStrings', $destinationFolder
    New-WDPublishSettings -UserId $UserName -Password $Password -ComputerName $destination -AllowUntrusted -FileName server.publishsettings -AgentType MSDepSvc -Site $Website
    Invoke-WDCommand -Command $cmd  -DestinationPublishSettings server -Verbose

#2


1  

I was getting this same message too. I looked in the Web Deployment logs in the Event Viewer > Microsoft Web Deploy. The Exception it was giving me was:

我也收到了同样的信息。我查看了事件查看器> Microsoft Web Deploy中的Web部署日志。它给我的例外是:

ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG Microsoft.Web.Deployment.DeploymentDetailedClientServerException: Failed to encrypt destination web.config: .... Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG. ---> System.Security.Cryptography.CryptographicException: Object already exists.

ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG Microsoft.Web.Deployment。DeploymentDetailedClientServerException:未能加密目标web。配置:....了解更多:http://go.microsoft.com/fwlink/?LinkId=221672 ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG。推荐- - - - - - > System.Security.Cryptography。CryptographicException:对象已经存在。

Googling this led me to this answer from "Just TFS": Release Management Agent not connecting

谷歌一下,我就得到了“仅TFS”的答案:发布管理代理不连接

Which said "The Deployer user (\) does not have access to the crypto store. On the server where the deployment agent is installed, navigate to this folder %ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\MachineKeys and give read/write access to \. – Just TFS Sep 3 '14 at 12:08"

它说“部署者用户(\)无法访问加密存储。在安装部署代理的服务器上,导航到这个文件夹%ALLUSERSPROFILE%\应用程序数据\微软\Crypto\RSA\ RSA MachineKeys,并给读/写访问\。-仅TFS 9月3日12:08

So I attempted to give my MS Deployer user account read/write to that MachineKeys folder but it denied me access to do so. I ended up adding the deployer user account as a local Administrator and that did the trick.

因此,我试图给我的MS Deployer用户帐户读/写到MachineKeys文件夹,但它拒绝我这样做。最后,我将部署者用户帐户添加为本地管理员,这就成功了。

Was able to deploy with it encrypting the web.config file successfully to the server.

能够使用它进行网络加密部署。配置文件成功地发送到服务器。

#1


2  

The problem seem to be that MSDeployEnableWebConfigEncryptRule doesn't work with MVC project that have multiple web.config files. Typically MVC project has Views/Web.Config file. This seems like a bug with MSDeploy.
My Workaround is to have a post deployment powershell script to perform same command on the destination server. See http://www.iis.net/learn/publish/using-web-deploy/web-deploy-powershell-cmdlets

问题似乎是,MSDeployEnableWebConfigEncryptRule不使用具有多个web的MVC项目。配置文件。典型的MVC项目有视图/Web。配置文件。这似乎是一个带有MSDeploy的错误。我的解决方案是使用后部署powershell脚本在目标服务器上执行相同的命令。参见http://www.iis.net/learn/publish/using-web-deploy/web-deploy-powershell-cmdlets

Powershell Script Sample:

Powershell脚本示例:

    Add-PSSnapin WDeploySnapin3.0
    $cmd = '%windir%\Microsoft.NET\Framework\v4.0.30319\ASPNET_REGIIS.exe -{0} {1} "{2}"' -f 'pef', 'connectionStrings', $destinationFolder
    New-WDPublishSettings -UserId $UserName -Password $Password -ComputerName $destination -AllowUntrusted -FileName server.publishsettings -AgentType MSDepSvc -Site $Website
    Invoke-WDCommand -Command $cmd  -DestinationPublishSettings server -Verbose

#2


1  

I was getting this same message too. I looked in the Web Deployment logs in the Event Viewer > Microsoft Web Deploy. The Exception it was giving me was:

我也收到了同样的信息。我查看了事件查看器> Microsoft Web Deploy中的Web部署日志。它给我的例外是:

ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG Microsoft.Web.Deployment.DeploymentDetailedClientServerException: Failed to encrypt destination web.config: .... Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG. ---> System.Security.Cryptography.CryptographicException: Object already exists.

ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG Microsoft.Web.Deployment。DeploymentDetailedClientServerException:未能加密目标web。配置:....了解更多:http://go.microsoft.com/fwlink/?LinkId=221672 ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG。推荐- - - - - - > System.Security.Cryptography。CryptographicException:对象已经存在。

Googling this led me to this answer from "Just TFS": Release Management Agent not connecting

谷歌一下,我就得到了“仅TFS”的答案:发布管理代理不连接

Which said "The Deployer user (\) does not have access to the crypto store. On the server where the deployment agent is installed, navigate to this folder %ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\MachineKeys and give read/write access to \. – Just TFS Sep 3 '14 at 12:08"

它说“部署者用户(\)无法访问加密存储。在安装部署代理的服务器上,导航到这个文件夹%ALLUSERSPROFILE%\应用程序数据\微软\Crypto\RSA\ RSA MachineKeys,并给读/写访问\。-仅TFS 9月3日12:08

So I attempted to give my MS Deployer user account read/write to that MachineKeys folder but it denied me access to do so. I ended up adding the deployer user account as a local Administrator and that did the trick.

因此,我试图给我的MS Deployer用户帐户读/写到MachineKeys文件夹,但它拒绝我这样做。最后,我将部署者用户帐户添加为本地管理员,这就成功了。

Was able to deploy with it encrypting the web.config file successfully to the server.

能够使用它进行网络加密部署。配置文件成功地发送到服务器。