Creating a host-named site collection programmatically

A host header is a third piece of information that you can use in addition to the IP address and port number to uniquely identify a Web domain or, as Microsoft calls it, an application server.

In SharePoint 2010, You can apply host headers at two different levels :

  • The Web application (IIS Web site) level
  • The site collection level

The following code snippet programmatically creates the host-named site collection with the URL in the SharePoint Server 2010 Web application with the URLhttp://sharepoint

SPWebApplication webApp = SPWebApplication.Lookup(new
SPSiteCollection sites = webApp.Sites;
SPSite Site = sites.Add(“”, “Training”,
“Training Site”, 1025, “STS#0”, “domain\ayman”,
“Ayman El-Hattab”, “”, “domain\marwan”,
“Marwan Tarek”,, true);

You can also use PowerShell to achieve the same results, for more info refer to :


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s