Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Gets the name of the server that hosts the site collection.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public ReadOnly Property HostName As String
Get
'Usage
Dim instance As SPSite
Dim value As String
value = instance.HostName
public string HostName { get; }
Property Value
Type: System.String
A string that contains the name of the host.
Remarks
When used in conjunction with an 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 that is running SharePoint Foundation, but if https://localhost is passed as the URL, then the property contains "localhost".
Examples
The following code example displays the host name for the current site collection.
Dim oSiteCollection As SPSite = SPContext.Current.Site
Response.Write(oSiteCollection.HostName)
SPSite oSiteCollection = SPContext.Current.Site;
Response.Write(oSiteCollection.HostName);