【问题标题】:Powershell Start-Website IISPowershell 启动网站 IIS
【发布时间】:2014-01-29 11:38:55
【问题描述】:

问题/疑问

我正在测试运行用于 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 问题"Cannot create a file" error when running Start-Website command in Powershell 提供了一个很好的线索。


编辑:

查看我的事件日志并检查答案后,我发现当 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 中删除了我的网站。完美安装 - 没有问题,自动启动。 第二次运行完全一样,第三次运行我得到上面的错误!

【问题讨论】:

  • 可以通过 UI 启动网站吗?
  • @DavidMartin 是的,效果很好。

标签: iis powershell redgate


【解决方案1】:

我猜 $RedGateWebSiteName 变量没有被赋值,假设日志消息用它的值替换了变量。从谷歌搜索来看,IIS“文件已存在”消息可能是错误的,因为从缺少 IP 地址绑定到无效的虚拟目录文件夹。

【讨论】:

  • 您是否尝试过检查系统的应用程序事件日志,看看是否有正当的原因导致网站无法启动?
【解决方案2】:

为什么需要脚本来启动网站?如果您使用的是 Red Gate 部署管理器,它会在部署 web 包(任何带有 web.config 文件的包)后启动网站。

可能是 $RedGateWebSiteName 的值替换没有发生,它可能需要双引号:

启动网站“$RedGateWebSiteName”

我这样说是因为你的错误信息是这样说的:

起始网站

当错误消息here 显示替换值时:

启动网站

【讨论】:

  • 谢谢你的回答,我试着在它周围加上“”然后结果是 start-website
【解决方案3】:

我在启动网站时遇到了完全相同的问题:

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.

很明显,服务没有启动,结果是真的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-13
    • 2019-01-02
    • 2014-07-24
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 2021-04-16
    • 2012-05-29
    相关资源
    最近更新 更多