Visual Studio 如果用户不是管理员,2017 Web 发布会失败,而同一用户可以在同一 Web 服务器上用于 VS2015 Web 发布

Visual Studio 2017 Web publishing fails if user is non-admin while the same user can be used for VS2015 web publishing on the same web server

我正在尝试使用 Visual Studio 2017 使用非管理员帐户将 ASP.NET 核心 Web 项目 发布到 IIS(远程服务器),我部署时出现以下错误:

Starting Web deployment task from source: manifest(D:\Projects\Own\AspNetCore\CoreWithAngularTrial\CoreWithAngularTrialApi\obj\Debug\netcoreapp1.1\PubTmp\CoreWithAngularTrialApi.SourceManifest.xml) to Destination: auto(). C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeploy.targets(134,5): Error : Web deployment task failed. (Connected to the remote computer ("...") 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. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.) 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 remote computer ("...") 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. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED. The remote server returned an error: (401) Unauthorized. Publish failed to deploy.

我有以下部署配置:

Publish method = Web deploy
Server = servername:8172/msdeploy.axd
Site name = Default Web Site/CoreWithAngularTestApi
User name = username
Password = ******

在同一网站(默认网站)下发布不同的应用程序 (ASP.NET MVC 5) 时完全相同的配置有效,因此发布配置在远程服务器上看起来是正确的。

username 成为本地管理员可以在 Visual Studio 2017 年解锁发布过程。

此外,发布配置文件 (*.pubxml) 几乎完全相同。

远程服务器上的事件查看器发现以下错误:

IISWMSVC_AUTHORIZATION_SERVER_NOT_ALLOWED

Only Windows Administrators are allowed to connect using a server connection. Other users should use the 'Connect To Site or Application' task to be able to connect.

Process:WMSvc User=username

问题: 如何启用 Visual Studio 2017 年的非管理网络发布?

我设法找出非管理员用户发布失败的原因。服务器设置正确,但 Visual Studio 发布似乎对待 ASP.NET 核心 Web 应用程序部署不同于 ASP.NET MVC 5 部署。

我必须在发布配置文件 xml 文件中明确指定网站名称。所以,而不是:

<MSDeployServiceURL>servername:8172/msdeploy.axd</MSDeployServiceURL>

我放

<MSDeployServiceURL>servername:8172/msdeploy.axd?Site=Default Web Site</MSDeployServiceURL>

注意:在 VS2017 中发布 MVC 5 项目时不会出现此问题。

此问题已修复:https://github.com/aspnet/websdk/issues/146

ASP.NET 核心项目使用一组不同的 Publish 目标(因此 MVC5 的行为发生了变化)。该项目在 GitHub - https://github.com/aspnet/websdk 可用。