Clone wiki

sitecore-automation / sitecore-sites

Sitecore Site Definition

Sitecore sites are defined in special file SiteDefinition.config. Of course you can add your sites directly in the web.config file but this is bad practice. Better is to keep all custom Sitecore settings in external files. Sitecore has greate patching system and is highly recommended to follow this way.

Information about Sitecore sites will come from site definition files. Each Sitecore installation contains file SiteDefinition.config.example located in App_Config\Include folder. Sample file content showed below.

2016-04-13_21-50-59.png

Explanation what all attributes purpose is you can found in 'web.config' file in the <sites><sites> node.All your site definition files should be located in the 'App_Config\Include' folder. If you have one file then all necessary changes can be done manually, but for example if your solution contains ten site definition files and each has one ore more site definition then manual changes and verification can be painful.

I decide to write Powershell script that will check all config files in specified location and returns array with Sitecore Sites.

Get-SitecoreSites

$webPath = "B:\Sitecore 8.2 rev. 160729\Website\App_Config\Include"

$sites = Get-SitecoreSites -Path $webPath -Verbose

This simple code return all sites objects defined in any config files.

get-sites.png

Lists of Sitecore sites can be used to automate some tasks in Powershell. For example you can write code for continuous configuration verification.

# Check if all sites on a Content Delivery server uses a web database
Get-SitecoreSites -Path $webPath -Verbose | Where-Object {$_.database -ne "web"}

Add-SitecoreBindings

You can automate add bindings base on site definition files.

$webPath = "B:\Sitecore 8.2 rev. 160729\Website\App_Config\Include"

$hosts = Get-SitecoreSites -Path $webPath | Select-Object -ExpandProperty hostName

Add-SitecoreBindings -Hosts $hosts -WebSite "BindingTests" -www  -Verbose

add+bindings.png

Remove-SitecoreBindings

With Remove-SitecoreBindings an IIS bindings can be removed.

$webPath = "B:\Sitecore 8.2 rev. 160729\Website\App_Config\Include"

$hosts = Get-SitecoreSites -Path $webPath | Select-Object -ExpandProperty hostName

Remove-SitecoreBindings -Hosts $hosts -WebSite "BindingTests" -Verbose

Updated