AddHost Method  

Add a new virtual host to the server virtual host table.


object.AddHost( VirtualHost, [VirtualPort], [Directory] )


A string which specifies the hostname that will be added to the virtual host table. This parameter must specify a valid hostname and cannot be a zero-length string.
An optional integer value which specifies the port number for the virtual host. If this parameter is specified, the value must be zero or the same value as the original port number that the server was configured to use. Port-based virtual hosting is currently not supported and this parameter is included for future use.
An optional string that specifies the root document directory for the virtual host. If this parameter is omitted or a zero-length string, the virtual host will use the same root directory that was specified when the server was started. This parameter may contain environment variables enclosed in % symbols.

Return Value

An integer value that specifies the host ID that is used to reference the virtual host. A return value of -1 indicates that an error has occurred.


Virtual hosting is a method for sharing multiple domain names on a single instance of a server. The client provides the server with the hostname that it has used to establish the connection, and that name is compared against a table of virtual hosts configured for the server. If the hostname matches a virtual host, the client will use the root directory and any virtual paths that have been assigned to that host.

When the server is first started, a default virtual host with an ID of zero is automatically created and is identified as httpHostDefault. This virtual host uses the same hostname, port number and root directory that the server instance was created with. The application should treat all other host IDs as opaque values and never make assumptions about how they are allocated.

The virtual host ID returned by this method can be used with the AddPath method to create a virtual path assigned to the host, the AddUser to create a virtual user, and the RegisterHandler and RegisterProgram methods which are used to register script handlers and CGI programs.

See Also

AddPath Method, AddUser Method, DeleteHost Method, RegisterHandler Method, RegisterProgram Method