[英]Powershell Start-Website IIS
问题/疑问
我正在测试运行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.
在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有人提到它的原因是在没有hostheader的情况下创建IIS网站。 我在尝试启动网站后添加了主机头。 让我们找到解决方案
编辑2:我在尝试启动网站后添加了主机名。 这导致该网站具有空主机名并且在IIS中存在冲突。 (或者别的地方)。 我已经更改了我的脚本以获取网站,添加主机名然后启动网站。 还添加了“ $RedgateWebsiteName"
而不是$RedGateWebSiteName.
现在完美运作!
编辑3:经过一系列测试后,我似乎最终得到了同样的错误。 一个部署没有问题,另一个部署确实有。
编辑4:我更新了脚本/错误/帖子。 在我点击安装后,我从IIS中删除了我的网站。 完美安装 - 没问题,自动启动。 第二次运行完全相同,第三次运行我得到上面的错误!
我猜测$ RedGateWebSiteName变量没有被赋值,假设日志消息用它的值替换变量。 从谷歌搜索,看起来IIS“文件已存在”消息可能是错误的,因为它发生的任何事情,从缺少IP地址绑定到无效的虚拟目录文件夹。
为什么需要脚本来启动网站? 如果您使用的是Red Gate Deployment Manager,它会在部署Web包(任何包含web.config文件的包)后启动网站。
可能是$ RedGateWebSiteName的值替换没有发生,它可能需要双引号:
开始网站“$ RedGateWebSiteName”
我这样说是因为您的错误消息说明了这一点:
开始网站<<<< $ RedGateWebSiteName
而这里的错误消息显示替换值:
start-website <<<<“MyWebsite”
我在启动网站时遇到了完全相同的问题:
Start-Website -Name MyWebSiteName
它不会开始。 当我尝试在IIS管理器中手动启动它时,它也无法启动,我收到此错误消息:
The World Wide Web Publishing Service (W3SVC) is stopped. Websites cannot be started unless the World Wide Web Publishing Service (W3SVC) is running.
很明显,服务没有启动,结果证明是真的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.