问题/问题
我正在测试Redgate部署脚本。在最后一步,它会启动一个网站:
import-module WebAdministration
$website = get-website | where-object { $_.name -eq $RedGateWebSiteName }
#(re)write HostName#
$binding = Get-WebBinding -Name $RedGateWebSiteName
Set-WebBinding -Name $RedGateWebSiteName -BindingInformation "*:80:*" -PropertyName HostHeader -Value $HostName
if ($website) {
Start-Website "$RedGateWebSiteName"
}
它以前一直可以正常工作,但现在在最近的几天之一出现了这个错误。
At D:\inetpub\Timeblockr-RedGate\Api\PostDeploy.ps1:15 char:15
+ Start-Website <<<< "$RedGateWebSiteName"
+ CategoryInfo : InvalidOperation: (:) [Start-Website], COMException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.IIs.PowerShell.Provider.StartWebsiteCommand
IIS错误
The World Wide Web Publishing Service (WWW Service) did not register the URL prefix http://*:80/ for site 3. The necessary network binding may already be in use. The site has been disabled. The data field contains the error number.
这个SO问题在PowerShell中运行Start-Website命令时出现“无法创建文件”错误提供了一个很好的线索,指明可能是什么原因。
编辑:
查看我的事件日志并检查答案后,我发现当Redgate自动尝试安装/启动网站时,我遇到了这个IIS错误:
The World Wide Web Publishing Service (WWW Service) did not register the URL prefix http://*:80/ for site 3. The necessary network binding may already be in use. The site has been disabled. The data field contains the error number.
在这个Serverfault页面:https://serverfault.com/questions/456217/the-world-wide-web-publishing-service-www-service-did-not-register-the-url,有人提到这是因为创建的IIS网站没有主机头。我在尝试启动网站后添加了主机头。让我们找到解决方案。 编辑2: 我在尝试启动网站后才添加主机名。这导致网站具有空主机名,在IIS中发生冲突(或其他地方)。 我已更改我的脚本以获取网站,添加主机名,然后启动网站。 还将"
$RedgateWebsiteName"
添加到$RedGateWebSiteName.
,现在完美运行!
编辑3:
经过一系列测试,我似乎最终遇到了同样的错误。一个部署没有问题,另一个部署有问题。
编辑4:
我已更新脚本/错误/帖子。
我从IIS中删除了我的网站,然后点击安装。完美安装-没有问题,自动启动。
第二次运行完全相同,第三次运行我收到上面的错误!