HostName Property

The HostName property of the SPSite class gets the name of the server that hosts the site collection.

Property Value

A string that contains the name of the host.

Remarks

When used in conjunction with the SPSite constructor, the HostName property contains a different value depending on the URL that is passed to the constructor. For example, if "http://" + System.Environment.MachineName is passed as the URL, the HostName property contains the name of the computer running Windows SharePoint Services, but if http://localhost is passed, then the property contains "localhost".

Example

The following code example displays the host name for the current site collection.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

Requirements

Platforms: Microsoft Windows Server 2003

Security: Code Access Security