I had some free time one night and decided to work on something that I'd had several people ask me about - extending a web application programmatically. Honestly I was surprised at how many people had specifically asked me to create this command. To accomplish this I created a new command: gl-extendwebapp. Note that I'm starting to prefix my commands (something I should always have been doing) and I will eventually set all commands to have this prefix so expect that breaking change to come soon. The code is actually not too bad - you basically create a new SPIisSettings object and add an SPServerBinding or SPSecureBinding object based on whether it's an SSL site or not. The only odd piece of my code is that I use a little bit of reflection so that I can fire the timer job using the same code that Microsoft uses when executed via the browser:
The syntax of the command can be seen below. Note that the vsname parameter is just the display name within IIS (also known as the server comment). The other fields are pretty self explanatory and match the fields seen via the browser:
C:\>stsadm -help gl-extendwebapp stsadm -o gl-extendwebapp Extends a web application onto another IIS web site. This allows you to serve the same content on another port or to a different audience Parameters: -url <url of the web application to extend> -vsname <web application name> -path <path> -loadbalancedurl <the load balanced URL is the domain name for all sites users will access in this SharePoint Web application> [-zone <default | intranet | internet | custom | extranet (defaults to Custom)>] [-port <port number (default is 80)>] [-hostheader <host header>] [-exclusivelyusentlm] [-allowanonymous] [-usessl]
The following table summarizes the command and its various parameters:
|Command Name||Availability||Build Date|
|gl-extendwebapp||WSS v3, MOSS 2007||Released: 3/31/2008
|Parameter Name||Short Form||Required||Description||Example Usage|
|url||Yes||The URL of the existing web application to extend.||-url http://portal|
|vsname||Yes||The virtual server name to use - this is the name that will appear in the IIS manager.||-vsname "New Portal - 80"|
|path||Yes||The physical path to store the web files in.||-path c:\moss\webs\newportal|
|loadbalancedurl||lburl||Yes||The load balanced URL is the domain name for all sites users will access in this SharePoint web application.||-loadbalancedurl http://newportal
|zone||No||The zone to use. Valid values are: default, intranet, internet, custom, extranet. If omitted defaults to custom. If a value is already in use then the following error will be returned: "An item with the same key has already been added."||-zone intranet|
|port||p||N||The port to bind the web application to. If not specified defaults to 80.||-port 80
|hostheader||N||The host header to use.||-hostheader newportal|
|exclusivelyusentlm||ntlm||N||Specifies to exclusively use NTLM authentication instead of Negotiate (Kerberos).||-exclusivelyusentlm
Specifies the default state for anonymous access during virtual server provisioning. The default setting is off, regardless of the current IIS setting. The administrator needs to explicitly turn on anonymous access.
IIS anonymous access must be on for pluggable authentication. Anonymous requests must make it through IIS to get to the ASP.NET authentication system.
There is no anonymous access choice when provisioning with forms-based authentication.
Allowing anonymous access in IIS does not automatically make all Microsoft Office SharePoint Server 2007 sites anonymously accessible. There is Web-level anonymous access control as well, which is also off by default. However, disabling anonymous access in IIS does disable anonymous access to all Office SharePoint Server 2007 sites on the Web application because IIS rejects the request before code even runs.
|usessl||ssl||No||Use Secure Sockets Layer (SSL). If you choose to use SSL, you must add the certificate on each server using the IIS administration tools. Until this is done, the web application will be inaccessible from this IIS Web Site.||-usessl
Here's an example of how to extend an existing web application:
stsadm -o gl-extendwebapp -url http://portal -vsname "New Portal - 80" -path c:\moss\webs\newportal -loadbalancedurl http://newportal -zone custom -port 80 -hostheader newportal
Update 11/5/2008: I fixed an issue where the PreferredInstanceId was not being set. Thanks to Michael (see comments) for pointing out the issue.