简体   繁体   English

Powershell Start-Website IIS

[英]Powershell Start-Website IIS

Problem/Question 问题/疑问

I'm test running a script for redgate deployment. 我正在测试运行redgate部署的脚本。 At the last step it starts a website: 在最后一步,它启动了一个网站:

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"
}

It always worked but now on one of the last days I get this error 它总是有效但现在在最后几天我得到了这个错误

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 error 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.

This SO question "Cannot create a file" error when running Start-Website command in Powershell gives a pretty good clue what it can be. 在Powershell中运行Start-Website命令时,这个问题“无法创建文件”错误提供了一个非常好的线索。


Edit: 编辑:

After viewing my event log and checking out the answers I found out that when Redgate automaticly tries to install/start the website i'm getting this IIS error: 在查看我的事件日志并查看答案后,我发现当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.

In this Serverfault : https://serverfault.com/questions/456217/the-world-wide-web-publishing-service-www-service-did-not-register-the-url someone its mentioning that the cause of that is that a IIS website gets created without hostheader. 在这个Serverfault中: https ://serverfault.com/questions/456217/the-world-wide-web-publishing-service-www-service-did-not-register-the-url有人提到它的原因是在没有hostheader的情况下创建IIS网站。 I'm adding the hostheader after I try to start the website. 我在尝试启动网站后添加了主机头。 Lets find the solution 让我们找到解决方案

Edit 2: I was adding the hostname after I tried to start the website. 编辑2:我在尝试启动网站后添加了主机名。 This caused that the website has e empty hostname and that conflicts in IIS. 这导致该网站具有空主机名并且在IIS中存在冲突。 (or somewhere else). (或者别的地方)。 I've changed my script to get the website, add the hostname and then start the website. 我已经更改了我的脚本以获取网站,添加主机名然后启动网站。 Also added " $RedgateWebsiteName" instead of $RedGateWebSiteName. 还添加了“ $RedgateWebsiteName"而不是$RedGateWebSiteName. Works perfectly now! 现在完美运作!

Edit 3: After a run of tests I seem to end up the same error. 编辑3:经过一系列测试后,我似乎最终得到了同样的错误。 The one deploy has no problems, the other deploy does has. 一个部署没有问题,另一个部署确实有。

Edit 4: I've updated the script / Error / Post. 编辑4:我更新了脚本/错误/帖子。 I deleted my site from IIS after that I clicked on install. 在我点击安装后,我从IIS中删除了我的网站。 Perfectly installed - No problems, automatic start. 完美安装 - 没问题,自动启动。 Second run exactly the same, third run I get the error above! 第二次运行完全相同,第三次运行我得到上面的错误!

I'm guessing the $RedGateWebSiteName variable had not been assigned a value, assuming the log message replaces the variable with its' value. 我猜测$ RedGateWebSiteName变量没有被赋值,假设日志消息用它的值替换变量。 From googling around, it looks like the IIS "file already exists" message may be erroneous as it happens because of anything from a missing IP address binding to an invalid virtual directory folder. 从谷歌搜索,看起来IIS“文件已存在”消息可能是错误的,因为它发生的任何事情,从缺少IP地址绑定到无效的虚拟目录文件夹。

Why do you need a script to start the website? 为什么需要脚本来启动网站? If you are using Red Gate Deployment Manager, it starts the website after the deploying a web package (any package with a web.config file it). 如果您使用的是Red Gate Deployment Manager,它会在部署Web包(任何包含web.config文件的包)后启动网站。

It could be that the value substitution for $RedGateWebSiteName is not taking place and it probably needs double quotes: 可能是$ RedGateWebSiteName的值替换没有发生,它可能需要双引号:

Start-Website "$RedGateWebSiteName" 开始网站“$ RedGateWebSiteName”

I say this because your error message says this: 我这样说是因为您的错误消息说明了这一点:

Start-Website <<<< $RedGateWebSiteName 开始网站<<<< $ RedGateWebSiteName

while the error message here displays the substituted value: 这里的错误消息显示替换值:

start-website <<<< "MyWebsite" start-website <<<<“MyWebsite”

I had the exact same problem, when starting the website with: 我在启动网站时遇到了完全相同的问题:

Start-Website -Name MyWebSiteName

and it would not start. 它不会开始。 When I tried to start it manually in IIS Manager, it wouldn't start either and I got this error message: 当我尝试在IIS管理器中手动启动它时,它也无法启动,我收到此错误消息:

The World Wide Web Publishing Service (W3SVC) is stopped.  Websites cannot be started unless the World Wide Web Publishing Service (W3SVC) is running.

This is pretty clear that the service is not started and it turned out to be true. 很明显,服务没有启动,结果证明是真的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM