SharePoint 2010 – Central Admin tooling to create host header site collections

Just like SharePoint 2007, you can create host-header based site collections in SharePoint 2010 as well. It means, that you do not necessarily need to create a site-collection under a managed path like /sites/, you can create multiple root-level site collections on same web-application/port by using host-header site collections. All you need to do is point your domain or sub-domain to your web-application and create a matching site-collection that you want.

But, just like in 2007, it is something that you do by using STSADM, and is not available on Central Admin UI in 2010 as well. Yeah, though you can now also use PowerShell to create one:

C:\PS>$w = Get-SPWebApplication http://sitename
C:\PS>New-SPSite -OwnerAlias "DOMAIN\jdoe" -HostHeaderWebApplication $w -Title "Contoso" -Template "STS#0"
This example creates a host header site collection. Because the template is provided, the root Web of this site collection will be created.

I’ve been playing with WCM in SharePoint 2010 more and more, and for that I preferred creating hosts file entries for desired domains and create site-collections by those headers – in my dev environment. I used PowerShell initially, but then got interested to build my own UI on Central Admin instead.

Developed with Visual Studio 2010

So I used new Visual Studio 2010 tooling to create an empty SharePoint 2010 project. Added an application page (there is no option to add _Admin page item in VS 2010 RC), that got created in Layouts “mapped” folder. Created a new Admin mapped folder for 14-“hive”, and moved my new page there instead. Yes, I didn’t change the base class for page, its just that it runs under _admin, but it is indeed a LayoutsPageBase inherited page.


To introduce a action-link in Central Admin console, I created following element:

   1:  <Elements xmlns="">
   2:    <CustomAction
   3:          Id="CreateSiteByHeader"
   4:          Location="Microsoft.SharePoint.Administration.Applications"
   5:          Title="Create site collections by host header"
   6:          GroupId="SiteCollections"
   7:          Sequence="15"
   8:          RequiredAdmin="Delegated"
   9:          Description="Create a new top-level web site, by host header" >
  10:      <UrlAction Url="/_admin/OfficeToolbox/CreateSiteByHeader.aspx"  />
  11:    </CustomAction>
  12:  </Elements>

Used Reflector to understand any special code behind createpage.aspx, and created a new for our purpose – CreateSiteByHeader.aspx. From there I quickly created a similar code behind, without all the fancy of Farm Config Wizard handling and dealt with alternate implementations of sealed classes! Goal was to create a professional looking and OOB-type experience. I also added Regex validation to ensure user types a valid domain name as header value. Below is the result…


Release @ Codeplex

I’ve released to WSP on OfficeToolbox @ Codeplex, and you can download from here.

Update - Latest release is now uploaded and works with RTM.

Hope you find it useful…

-- Sharad


Comments have been disabled for this content.