Powershell Start-Website IIS - iis

Problem/Question
I'm test running a script for redgate deployment. 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
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.
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:
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. 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. This caused that the website has e empty hostname and that conflicts in 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. Works perfectly now!
Edit 3:
After a run of tests I seem to end up the same error. The one deploy has no problems, the other deploy does has.
Edit 4:
I've updated the script / Error / Post.
I deleted my site from IIS after that I clicked on install. 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. 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.

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).
It could be that the value substitution for $RedGateWebSiteName is not taking place and it probably needs double quotes:
Start-Website "$RedGateWebSiteName"
I say this because your error message says this:
Start-Website <<<< $RedGateWebSiteName
while the error message here displays the substituted value:
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:
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.

Related

APS.net core 2.2 - configuration to deploy to multiple iis with multiple sites

I have been really struggling with this. There is a lot of info, but can't seem to figure out the basics to get started.
In ASP.Net, I would have done all this with different web.config files.
This is what the end result of what I want is.
I have a single server with IIS on it. (say www.mysite.com)
I have 3 versions of the ASP.net core web site
www.mysite.com/PROD
www.mysite.com/DEMO
www.mysite.com/TEST
I am using Web Deploy from VS to Publish these to the server. I would like to have 3 different Publish profiles. Each will use a different configuration and publish to the appropriate web site.
The end result should have these differences
PROD:
ASPNETCORE_ENVIRONMENT : Production
Connection string : ... myDB_Prod
SiteName : "The Real Site"
DEMO:
ASPNETCORE_ENVIRONMENT : Production
Connection string : ... myDB_Demo
SiteName : "The Demo Site"
TEST
ASPNETCORE_ENVIRONMENT : Development
Connection string : ... myDB_Test
SiteName : "The Test Site"
LOCAL DEV
Use ISSExpress
ASPNETCORE_ENVIRONMENT : Development
Connection string : ... myLocalDB
SiteName : "Local Dev"
Note. This is made up, but would answer my questions. It is not what I am really doing, so please don't comment on that. I would actually really like to be able to turn on Development by changing something in a config file on the server without deploying (say in the web.confg!)
In my research, I am getting really confused with all the various places to set config. There also is changes in 2.2 and that is throwing me off.
I have been reading the MS Docs, but I must be missing something. Not sure where to start. appsettings.json, web.config, other config files, etc.

How do I modify the Site Collection in SharePoint 2013?

When I try to open a form published from InfoPath I now get this error:
"The following location is not accessible, because it is in a different site collection:
https//portal/sites/forms/Daily%20Activity/Forms/template.xsn?SaveLocation=https//portal.alamedacountyfire.org/sites/forms/Daily%20Activity/&Source=https//portal.alamedacountyfire.org/sites/forms/Daily%2520Activity/Forms/AllItems.aspx&ClientInstalled=false&OpenIn=Browser&NoRedirect=true&XsnLocation=https//PORTAL/sites/forms/Daily%20Activity/Forms/template.xsn."
Correlation ID:12c0ab9c-caff-80a8-f1b4-64d81dcfa6ea
Following are some options that you can try:
1) Save the form template (.xsn) as the source files in the publish options. Look at the manifest file in notepad and see if you can find a reference to the incorrect location. If so, correct it and Republish the form.
2) Clear the InfoPath cache on that machine. Start->Run "infopath /cache clearall"
3) See if the site collection has a managed path, if so, give the proper url while publishing. The XSN might be getting deployed on the root site and throws error since the intended list does'nt exist.
I found this worked for me. Got the answer from another post.
"I had a similar problem and found it was due to the request management service routing from my web application host header to the server name.
There was a routing rule in my request management settings. I just disabled routing and the problem went away. I used the following powershell to disable it. "
$w = Get-SPWebApplication "http://webapphostname"
$r = $w | Get-SPRequestManagementSettings
$r.RoutingEnabled = $false
$r.Update()
You may want to configure it rather than disable it. Here’s a good resource to get you started:
http://www.harbar.net/articles/sp2013rm1.aspx

Error creating IIS WebApplication

I added a webApplication Under Default website using powershell as follows:
function CreateWebApplication([string]$WebApplicationName,[string]$AppPoolName,[string]$PhysicalPath)
{
try
{
New-WebApplication -Name $WebApplicationName -Site 'Default Web Site' -PhysicalPath $PhysicalPath -ApplicationPool $AppPoolName
Write-Host "Created WebApplication :" $WebApplicationName
}
catch [Exception]
{
write-host $_.Exception.Message `n;
}
}
Its getting created fine,But when i am seeing this in IIS,it has only two section Names IIS and management.but if same thing i do from IIS console,three sections named ASP.net,IIS and management are added.Why i am not getting third section.Another thing if i am trying to enable directory browsing on same,its giving an error that unable to retrieve directory browsing giving some problem with applicationhost.config file.But when i am trying to find applicationhost.config file,its not there in the asked location "C:\Windows\System32\inetsrv".What is going wrong here i am not able to fin out.
Please help :)
The application pool is most likely not being created with a clr version.
If you open the application pool from IIS and look at the .NET version it will say
No managed code.
You can create the app pool and specify the managedRuntime version.

TermStore Count is 0

Overview
I am observing a really strange behaviour with code which attempts to retrieve the TermStore from the TaxonomySession. The code looks like this:
using (SPSite mySite = new SPSite(url))
{
TaxonomySession session = new TaxonomySession(mySite);
// Get all the TermStores associated with the provided site.
TermStoreCollection stores = session.TermStores;
Console.WriteLine(stores.Count);
Here is the issue:
The above code does not return any TermStores, i.e. the count is zero
If I run the following PowerShell script from the same command prompt, I get 1 TermStore in the count.
$site = new-object Microsoft.SharePoint.SPSite("https://mysite")
$session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$session.TermStores.Count
I have tried the following:
My Managed Metadata Application Proxy is a part of the default proxy group
The administrator for the Managed Metadata Service is configured correctly
The permissions for the Managed Metadata Service are configured correctly
The Managed Metadata application pool is running under the farm account
Modifying the code above to run under elevated privileges
The weird thing is that the first block of code above DOES NOT retrieve any TermStore(s) when compiled as an executable and invoked from a command window, which is running under the farm credentials. IN THE SAME window, I can copy and paste the second block of the equivalent PowerShell scripts and have it run!
Also, this issue is only happening on our Production environment. The same executable ran successfully on our DEV, TEST and Pre Prod environments.
Any help at this stage will be much appreciated.
We encountered exactly the same issue in our test environment. But, our development servers are working as expected. My colleague was able to narrow down the issue and resolve it by updating hotfix available in Microsoft support.
The following are the details of the hotfix and information he could come across while researching on that particular issue.
Support download link
For additional information:
http://chrisforbesblogs.net/2009/12/02/the-managed-metadata-service-or-connection-is-currently-not-available
http://expectedexception.wordpress.com/2011/06/15/the-managed-metadata-service-or-connection-is-currently-not-available-the-application-pool-or-managed-metadata-web-service-may-not-have-been-started-please-contact-your-administrator/
Please consult your system administrator before updating any hotfix to servers. Hope this help you to fix the issue in your production environment.

WMI/PowerShell Bug: why is CreateSite creating *two* sites all of the sudden?

I have a simple PowerShell script that uses WMI to create a web site on a Vista box. Yes, I know PowerShell has an IIS provider for working with IIS 7, but this script must also support IIS 6.0, so that rules that out.
Anyway, the script was working just fine, but all of the sudden (and I mean that literally, I made zero code changes to the script) it started creating a second, broken site for every call to the CreateNewSite method. Below is the script. Anyone have any ideas?
$path = "C:\My Path\WebSite"
$site = "TestSite"
$hostHeader = "demo.blah.com"
$service = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsWebService"
$bindingClass = [wmiclass]'root\MicrosoftIISv2:ServerBinding'
$bindings = $bindingClass.CreateInstance()
$bindings.IP = ""
$bindings.Port = "80"
$bindings.Hostname = $hostHeader
$result = $service.CreateNewSite($site, $bindings, $path)
The above script was just creating a site named 'TestSite', but now it's also creating a site called 'SITE_1786339847' (the number changes, but it's always similar to that). I have stepped through the script executing one line at a time, and neither site is created until the CreateNewSite method is invoked. Is WMI just buggy?
Whoops, answered my own question. I checked the raw IIS 7.0 configuration file and found an orphaned virtual directory that was associated to a site with the ID 1786339847. When I removed that virtual directory from the configuration file, the script started working correctly again.
In case anyone runs into something similar, grab the site ID for the bad site from IIS Manager before deleting it, then open up C:\Windows\system32\inetsrv\config\applicationHost.config. Scan the file for that ID and look for any orphaned references to it. Be sure you have a backup first.

Resources