Recipe12.3.Creating Web Sites


Recipe 12.3. Creating Web Sites

Problem

You want to create a web site.

Solution

Using a graphical user interface

To create a new web site from scratch using a wizard, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the server node.

  3. Right-click on the Web Sites node, select New Web Site Creation Wizard, and click Next.

  4. Type a descriptive name for your site and click Next.

  5. Assign an IP address to your site and click Next.

  6. Specify the path to the home directory for your site, decide whether to allow anonymous access to your site, and click Next.

  7. Specify web permissions to control access to your site and click Next, then Finish.

To create a new web site using a previously saved configuration file, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the server node.

  3. Right-click on the Web Sites node and select New

    Specify the path to the XML file containing your saved IIS configuration, click Read File, select the web site you want to import, and click OK.

  4. If the saved configuration was password protected when it was created, you'll be prompted here for a password; enter it and click OK.

  5. Right-click on the new web site and select Start.

Using a command-line interface

The following command creates a new web site named Human Resources on server with IP 216.44.65.8 and root directory D:\HR:

> iisweb /create D:\HR "Human Resources" /i 216.44.65.8

The following command creates a new site named My Company with root directory D:\Corp and IP address "All Unassigned," effectively making My Company the new default web site on the server:

> iisweb /create D:\Corp "My Company"

The following command creates a site on a standalone server named web04 using local credentials for that computer and leaving the site in a stopped state:

> iisweb /create D:\Finance "Accounting Department" /i 216.44.65.8 /dontstart /s web01 /u web04\Administrator /p <password>

The following command creates a site by importing a previously saved password-protected site configuration file named hr.xml:

> iiscnfg /import /f D:\hr.xml /d <password> /sp /lm/w3svc/1525757177 /dp /lm/w3svc/2 /child

The ID number 1525757177 for this site can be found by opening the XML file in Notepad and examining the Location attribute of the IisWebServer tag. For example:

<IIsWebServer    Location ="/LM/W3SVC/1525757177"         AuthFlags="0"         ServerAutoStart="TRUE"         ServerBindings="172.16.12.50:80:"         ServerComment="Human Resources"     > </IIsWebServer>

You can also retrieve this identifier from IIS Manager by clicking the Web Sites folder in the left pane. The list of web sites and their identifiers will be shown in the right pane.


Using VBScript
' This code creates a web site. ' ------ SCRIPT CONFIGURATION ------ strComputer = "<ServerName>" ' computer to connect to strSiteName = "<SiteName>"   ' web site description strRootDir = "<DirPath>"     ' root directory for the web site ' The following parameters are optional ' strPort = "<PortNumber>"     ' port for the web site ' strIP = "<IPAddress>"        ' IP address used for the site ' strHostHeader = "<HostName>" ' host header name for the site ' strSiteID = 1234             ' site ID (default is to auto-generate) ' ------ END CONFIGURATION --------- set objIIS = GetObject("IIS://" & strComputer & "/W3SVC" ) objServerBindings = Array(0) objServerBindings(0) = strIP & ":" & strPort & ":" & strHostHeader strNewSiteID = objIIS.CreateNewSite(strSiteName, objServerBindings, _                                     strRootDir, strSiteID) WScript.Echo "Successfully created web site " & strSiteName & _              " with ID " & strNewSiteID

Discussion

If you leave the IP address for your new site as All Unassigned, your new site will be the default web site for your computer, which is the web site the server returns when a browser tries to access an IP address not currently assigned to another site. For example, if a computer has three IP addresses 172.16.12.50, 172.16.12.51, and 172.16.12.52 and only the first address has been assigned to a site, then opening the URLs http://172.16.12.51 or http://172.16.12.52 will return the default web site. It's a good idea to have a default web site configured with general contact information about your company on a server that will be hosting many sites. Note that if there is already a web site that has All Unassigned for its IP address (such as the Default Web Site created when IIS is installed) then if you assign All Unassigned to another site you won't be able to start that site.

Host headers are a feature of the HTTP/1.1 specification and allow IIS to host multiple web sites that have the same IP address and port number but different DNS identities. You can't use host headers for sites that use SSL, however, and to use host headers you must have DNS name resolution working on your network. Also, don't assign any host header names to the Default Web Site. One good side of host headers is that when you have thousands of web sites hosted on a single IIS computer, using host headers to identify them incurs a smaller performance hit than using individual IP addresses.

Using VBScript

The one tricky thing about this code is setting up the ServerBindings array. For whatever reason, instead of making the web site IP address, port, and host header part of the parameters to the CreateNewSite method, they must be concatenated together in an array element and separated by a colon.

See Also

Recipe 12.4, Recipe 12.17, MS KB 304187 (IIS: Home Directory Cannot Point to Mapped Drives), and MS KB 816568 (HOW TO: Manage Web Sites and Web Virtual Directories by Using Command-Line Scripts in IIS 6.0)



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net