排查 Visual Studio 的 Web 部署问题

作者 :Apurva Joshi

此疑难解答中使用的工具:

  • NA

此信息仅供参考。 Microsoft 不做任何明示或暗示的担保。

概述

以下步骤逐步讲解尝试从 Visual Studio 发布到未通过 Web 部署正确配置的服务器时可能会遇到的一系列错误。 若要收集下面的屏幕截图和错误,我在 Visual Studio 2010 SP1 中使用了新的 ASP.Net MVC 3 项目。 目标服务器是使用 IIS 的 Windows Server 2008 R2 SP1 的干净安装。 没有完成其他配置。

“无法连接”错误

你可能会遇到的第一个错误类似于 Visual Studio 输出窗口中下面的屏幕截图。 为了便于阅读,将在屏幕截图下方重现消息的全文。

Visual Studio 中错误列表输出的屏幕截图。

Web deployment task failed.(Could not connect to the destination computer ("deployserver").On the destination computer, make sure that Web Deploy is installed and that the required process("The Web Management Service") is started.)
This error indicates that you cannot connect to the server. Make sure the service URL is correct,firewall and network settings on this computer and on the server computer are configured properly,and the appropriate services have been started on the server.
Error details:
Could not connect to the destination computer ("deployserver"). On the destination computer,
make sure that Web Deploy is installed and that the required process
("The Web Management Service") is started.
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period
of time, or established connection failed because connected host has failed to respond 1.1.1.1:8172

此错误中突出显示的文本 (,下面的其他错误) 是了解问题性质的关键。 Web 部署未从服务器收到回复,因此 Visual Studio 无法区分多个可能的原因。 因此,它会提供要尝试的内容列表。

是否已安装 Web 管理服务? 在 IIS 服务器上,打开 Internet Information Services Manager 并选择计算机名称节点。 在“功能”视图中,向下滚动到“管理”部分并查找以下图标:

“I S 管理器权限”图标、“I S 管理器用户”图标和“管理服务”图标的屏幕截图。

如果没有,则需要通过“添加角色服务”对话框安装管理服务。 也可以通过“产品”选项卡中的“Web 平台安装程序”安装它。在左侧列中选择“服务器”,然后选择“IIS:管理服务”。 请注意,安装管理服务后,需要启动它,因为它不会自动启动。 为此,请双击“管理服务”图标。 显示管理服务窗格后,单击右侧“操作”窗格中的“开始”。

是否已通过 Windows 防火墙允许 Web 管理服务? 在服务器上安装 Web 管理服务时,名为 Web 管理服务的入站防火墙规则 (HTTP 流量传入) 。 转到具有高级安全性的 Start-AdministrativeTools> -> Windows 防火墙,验证是否已启用此规则。 单击“入站规则”,在列表中查找 Web 管理规则。 应为所有配置文件启用它。 如果使用第三方防火墙,则需要确保允许端口 8172 上的入站连接。

服务 URL 是否正确?

默认情况下,Web 管理服务侦听端口 8172,但这可以更改。 检查正在使用哪个端口的最简单方法是打开上述管理服务窗格,并查看“连接”部分中的 IP 和端口信息。 如果端口已更改为 8172 以外的其他端口,则需要确保通过防火墙允许新端口,并更新 Visual Studio 发布设置中的服务 URL 以使用新端口。

Visual Studio 中“错误列表”屏幕的屏幕截图。

Web deployment task failed.(Could not connect to the destination computer ("deployserver") using
the specified process ("The Web Management Service") because the server did not respond.
Make sure that the process ("The Web Management Service") is started on the destination computer.)
Could not connect to the destination computer ("deployserver") using the specified process
("The Web Management Service") because the server did not respond. Make sure that the process
("The Web Management Service") is started on the destination computer.
The remote server returned an error: (403) Forbidden.

此消息有点误导。 它指出服务器未响应,但 403 错误指示 Web 部署可以联系服务器,但请求被主动拒绝。 Web 管理服务的 HTTP 日志可以帮助确认请求到达服务器,并提供有关失败的实际请求的详细信息。 默认情况下,可以找到 %SystemDrive%\Inetpub\logs\WMSvc 此日志。 与其他 IIS 日志一样,数据不会立即写入日志,因此可能需要等待几分钟才能查看请求,或重启 Web 管理服务刷新日志。

在 WMSVC 日志中,上面的错误如下所示

2011-06-02 17:59:05 192.168.0.211 POST /msdeploy.axd site=default%20web%20site 8172 - 192.168.0.203 - 403 6 5 1669

日志中的 403 后面的“6”是子状态代码,表示“IP 地址被拒绝”。 (可以在以下位置找到 IIS 的状态和子状态代码的完整列表 https://support.microsoft.com/kb/943891

管理服务是否配置为允许远程连接?

这是 403.6 响应最有可能的原因。 双击“管理服务”图标,并验证是否选中了“启用远程连接”。 必须停止服务进行更改,因此请务必在完成后重启该服务。

“管理服务”对话框的屏幕截图。

是否已为管理服务配置 IP 限制?

可能会收到 403 错误的另一个常见原因是管理服务已配置为拒绝客户端的 IP。 默认情况下,只要允许远程连接,它就配置为允许所有 IP。 可以通过双击管理服务图标来检查 IP 限制。 任何配置的 IP 限制规则都将位于页面底部的 IPv4 地址限制

Visual Studio 中“错误列表”页的屏幕截图。错误详细信息处于焦点。

Web deployment task failed.(Could not connect to the destination computer ("deployserver").
On the destination computer, make sure that Web Deploy is installed and that the required process
("The Web Management Service") is started.
The requested resource does not exist, or the requested URL is incorrect.
Error details: Could not connect to the destination computer ("deployserver").
On the destination computer, make sure that Web Deploy is installed and that the required process
("The Web Management Service") is started.
The remote server returned an error: (404) Not Found.

404 错误指示 Web 部署能够联系服务器上的 Web 管理服务,但找不到所需的内容。 首先需要确认 Web 部署尝试连接到的资源。 应在 WMSVC 日志中看到如下所示的条目

2011-05-12 15:21:50 192.168.0.211 POST /msdeploy.axd site=default%20web%20site 8172 - 192.168.0.203 - 404 7 0 1606

Msdeploy.axd 是 Web 部署请求的处理程序。

是否已安装 Web 部署?

可以通过转到“程序和功能”控制面板并在已安装的程序列表中查找 Microsoft Web Deploy 2.0 来验证是否已安装 Web 部署。 如果不存在,可以通过“产品”选项卡通过 Web 平台安装程序安装它。它列为 Web 部署工具 2.1。 还应确保 Web 部署代理 服务 (MsDepSvc) 正在运行。

是否已安装 Web 部署处理程序?

如果已安装 Web 部署,但仍收到此错误,请确保已安装 Web 部署中的IIS 7 部署处理程序功能。 在“程序和功能”控制面板中,找到 Microsoft Web Deploy 2.0,右键单击并选择“更改”。 在出现的向导中,单击第一页上的“下一步”,然后在第二页上选择“更改”。 添加IIS 7 部署处理程序及其下的所有内容。

Microsoft Web 部署 2 点 0 安装程序对话框的屏幕截图。突出显示Web 部署框架。

单击“下一步”以完成向导。 进行此更改后,需要重启 Web 管理服务。

委派规则的错误

正确配置 Web 部署和 Web 管理服务后,需要设置委派规则以允许用户更新内容。 对于权限问题,Visual Studio 中可能会出现几种不同的错误。 例如:

Visual Studio 中显示权限问题错误的错误列表的屏幕截图。

Web deployment task failed.(Connected to the destination computer ("deployserver")
using the Web Management Service, but could not authorize.
Make sure that you are using the correct user name and password, that the site you are connecting
to exists, and that the credentials represent a user who has permissions to access the site.
Make sure the site name, user name, and password are correct. If the issue is not resolved,
please contact your local or server administrator.
Error details:
Connected to the destination computer ("deployserver") using the Web Management Service,
but could not authorize. Make sure that you are using the correct user name and password,
that the site you are connecting to exists, and that the credentials represent a user who
has permissions to access the site.
The remote server returned an error: (401) Unauthorized.

在 WMSvc 日志中,你将看到

2011-05-12 15:50:12 192.168.0.211 POST /msdeploy.axd site=default%20web%20site 8172 - 192.168.0.203 - 401 2 5 1653
2011-05-12 15:50:12 192.168.0.211 POST /msdeploy.axd site=default%20web%20site 8172 user1 192.168.0.203 - 401 1 1326 124

Visual Studio 输出中突出显示的 http 状态是“拒绝访问”错误。 错误日志中突出显示的 win32 状态映射到“登录失败:未知用户名或密码错误”,因此这是一个简单的登录失败。 如果用户经过身份验证,但没有发布所需的权限,则日志条目将如下所示

2011-05-12 15:55:38 192.168.0.211 POST /msdeploy.axd site=default%20web%20site 8172 - 192.168.0.203 - 401 2 5 0

若要允许此用户发布,需要根据以下说明设置委派: https://www.iis.net/learn/publish/using-web-deploy/configure-the-web-deployment-handler

如果帐户能够登录,但尚未授予发布内容所需的权限,你将看到

Visual Studio 中“错误列表”页的屏幕截图,其中显示了与用户权限相关的错误。

Web deployment task failed. (Unable to perform the operation ("Create Directory")  for the specified
directory ("bin"). This can occur if the server administrator has not authorized this operation for
the user credentials you are using.

WMSvc 日志将显示这些请求的 HTTP 200 响应。 幸运的是,Web 部署 2.1 还会将信息写入 Microsoft Web 部署服务日志。 若要查看它,请打开事件查看器并转到应用程序和服务日志 ->Microsoft Web 部署。

事件查看器菜单的屏幕截图。突出显示 Microsoft Web 部署。

对于此特定错误,事件日志包含为简洁) 截断的额外详细信息 (:

User: DEPLOYSERVER\User1
Client IP: 192.168.0.203
Content-Type: application/msdeploy
Version: 8.0.0.0
MSDeploy.VersionMin: 7.1.600.0
MSDeploy.VersionMax: 7.1.1070.1
MSDeploy.Method: Sync
MSDeploy.RequestId: 50de0746-f10d-4640-9b3d-4ba773520e38
MSDeploy.RequestCulture: en-US
MSDeploy.RequestUICulture: en-US
Skip: objectName="^configProtectedData$"
Provider: auto, Path: 
Tracing deployment agent exception. Request ID '50de0746-f10d-4640-9b3d-4ba773520e38'. Request Timestamp: '5/12/2011 9:18:12 AM'. Error Details:
Microsoft.Web.Deployment.DeploymentDetailedUnauthorizedAccessException: Unable to perform the operation ("Create Directory")
for the specified directory ("C:\inetpub\wwwroot\bin"). This can occur if the server administrator has not authorized this
operation for the user credentials you are using.
---> Microsoft.Web.Deployment.DeploymentException: The error code was 0x80070005. ---> System.UnauthorizedAccessException:
Access to the path 'C:\inetpub\wwwroot\bin' is denied.
   at Microsoft.Web.Deployment.Win32Native.RaiseIOExceptionFromErrorCode(Win32ErrorCode errorCode, String maybeFullPath)
   at Microsoft.Web.Deployment.DirectoryEx.CreateDirectory(String path)
   at Microsoft.Web.Deployment.DirPathProvider.CreateDirectory(String fullPath, DeploymentObject source)
   at Microsoft.Web.Deployment.DirPathProvider.Add(DeploymentObject source, Boolean whatIf)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---

此消息告知需要为此特定错误授予权限的位置。 Visual Studio 中可能看到的另一个权限错误是

Visual Studio 中“错误列表”页的屏幕截图,其中焦点有权限错误。

Web deployment task failed.((5/12/2011 11:31:41 AM) An error occurred when the request was processed on the remote computer.)
(5/12/2011 11:31:41 AM) An error occurred when the request was processed on the remote computer.
The server experienced an issue processing the request. Contact the server administrator for more information.

此特定错误不会让你继续执行很多操作,但如果查看事件查看器中的 Web 部署错误日志,图片会变得更加清晰。

User: DEPLOYSERVER\User1
Client IP: 192.168.0.203
Content-Type: application/msdeploy
Version: 8.0.0.0
MSDeploy.VersionMin: 7.1.600.0
MSDeploy.VersionMax: 7.1.1070.1
MSDeploy.Method: Sync
MSDeploy.RequestId: 63b2f3d1-1817-444f-8280-9fa4f6f85d53
MSDeploy.RequestCulture: en-US
MSDeploy.RequestUICulture: en-US
Skip: objectName="^configProtectedData$"
Provider: auto, Path: 
Tracing deployment agent exception. Request ID '63b2f3d1-1817-444f-8280-9fa4f6f85d53'. Request Timestamp: '5/12/2011 9:31:41 AM'. Error Details:
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
   at System.Security.AccessControl.Win32.SetSecurityInfo(ResourceType type, String name, SafeHandle handle, SecurityInfos securityInformation, SecurityIdentifier owner, SecurityIdentifier group, GenericAcl sacl, GenericAcl dacl)
   at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)
   at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections, Object exceptionContext)
   at Microsoft.Web.Deployment.FileSystemSecurityEx.Persist(String path)
   at Microsoft.Web.Deployment.SetAclProvider.Add(DeploymentObject source, Boolean whatIf)
   at Microsoft.Web.Deployment.DeploymentObject.Update(DeploymentObject source, DeploymentSyncContext syncContext)
   at Microsoft.Web.Deployment.DeploymentSyncContext.HandleUpdate(DeploymentObject destObject, DeploymentObject sourceObject)
   at Microsoft.Web.Deployment.DeploymentSyncContext.SyncChildrenOrder(DeploymentObject dest, DeploymentObject source)
   at Microsoft.Web.Deployment.DeploymentSyncContext.ProcessSync(DeploymentObject destinationObject, DeploymentObject sourceObject)

由此可见,User1 无权设置安全信息。 在这种情况下,用户对内容没有“修改”权限。 向内容授予“更改权限”可解决问题。

其他资源