Microsoft IIS 6.0Administrator's Consultant

The metabase is one of the most important components in an IIS installation. The metabase is where IIS stores configuration settings for sites and virtual servers. The metabase also contains default settings for sites and virtual servers, such as the global Web Sites properties.

Tip

When you work with the metabase files, it’s important to that you shouldn’t use the Encrypting File System (EFS) to encrypt them. Sensitive values in the metabase are already encrypted, and if you encrypt the metabase files themselves, you’ll unnecessarily slow down IIS.

Examining and Editing the Metabase

In IIS 6.0, IIS stores the metabase configuration in structured Extensible Markup Language (XML) files. The main configuration information is in a file that’s located in the %SystemRoot%\system32\Inetsrv directory and is named MetaBase.xml. You’ll also find a related file called MBSchema.xml, shown in Figure 15-2. MBSchema.xml is an XML Schema file, which tells IIS about the structure of the MetaBase.xml file.

Figure 15-2: MetaBase.xml is a structured XML file that can be viewed in any standard text editor.

You can examine and work with the Metabase files in any standard text editor. However, you should know several things before you do this:

If you plan to use scripts to work with the metabase, you need to understand the metabase’s structure and know how to locate properties. Every XML element that corresponds to a metabase property has a Location property that specifies the element’s path in the metabase hierarchy. The hierarchy follows this convention:

/LM/Service/Website

where LM is a key that represents the local machine; Service is a placeholder that represents an Internet service, such as W3SVC or MSFTPSVC; and Website is a placeholder that represents the site or virtual server instance.

To see how metabase paths are used, consider the following example. The metabase path /LM/W3SVC/1 is the path to the Web site instance installed on the local machine with the tracking ID of 1. In the MetaBase.xml file, you could locate the entries related to this path, and they might look like this:

<IIsWebServerLocation ="/LM/W3SVC/1" AppPool DefaultDoc="Default.htm,Default.asp,index.htm, iisstart.htm,Default.aspx" ServerBindings=":80:" ServerComment="Default Web Site" ServerSize="1" > </IIsWebServer>

If you’re familiar with HTML or XML, you’ll know that IISWebServer is an XML element. Each property of this XML element corresponds to a specific metabase property. The value assigned to the property is the current value of the related metabase property. For example, according to the previous code sample, the metabase property ServerSize is set to 1 and the complete metabase path to this property is:

/LM/W3SVC/1/ServerSize

The hierarchy can extend downward as well. For example, the metabase path to the root directory or a Web site follows this convention:

/LM/Service/Website/Root

where LM is a key that represents the local machine; Service is a placeholder that represents an Internet service, such as W3SVC or MSFTPSVC; Website is a placeholder that represents the site or virtual server instance; and Root is the virtual directory root of the server instance.

If you examine the MetaBase.xml file, you’d find an IIsWebVirtualDir element for the root directory of the first Web server instance. The stored values might look like this:

<IIsWebVirtualDirLocation ="/LM/W3SVC/1/ROOT" AccessFlags="AccessRead | AccessScript" AppFriendlyName="Default Application" AppIsolated="2" AppPool AppRoot="/LM/W3SVC/1/ROOT" Path="d:\inetpub\wwwroot" > </IIsWebVirtualDir>

Here, the path to any property is the Location value plus the property name, such as:

/LM/W3SVC/1/ROOT/AppIsolated

When you work with metabase properties, the inheritance rules discussed in previous chapters still apply. Properties that you set at the Server level can apply to sites, directories within a site, and subdirectories within a directory. Similarly, child nodes could inherit properties that you set for a site or a directory. Inheritance is automatic and works just as discussed in previous chapters.

Modifying Metabase Properties

As you can probably imagine, you can set hundreds of metabase properties. The ones you’ll work with the most relate to global settings for Web servers. You’ll set these properties in the metabase location /LM/W3SVC.

Global values for the Web Service are set using the IIsWebService element in the MetaBase.xml file. The Location attribute of this element corresponds to the metabase location (/LM/W3SVC). Values for individual Web sites and virtual directories are set using the IIsWebServer and IIsWebVirtualDir elements respectively. The Location attribute of these elements is set according to the specific element’s location in the metabase hierarchy.

The properties you’ll want to work with include the following:

Scripting the Metabase

Windows scripts provide another technique you can use to work with the metabase. To access metabase properties in a Windows script, you use the Active Directory Services Interface (ADSI) provider for IIS. This provider allows you to manipulate the IIS administrative objects. Key administrative objects that you’ll work with include IIsComputer, IIsWebServer, and IIsFtpServer. These objects correspond to the like-named elements in the MetaBase.xml file.

You can use the IIsComputer object to set global IIS properties and to manage metabase backups. Keep in mind that all child nodes (sites, directories, and others) can inherit global properties. The IIsComputer object is an ADSI container object that has this AdsPath:

IIS://MachineName

where MachineName can be any computer name or LocalHost, such as

IIS://engsvr01

In VBScript, you could get the IIsComputer object for ENGSVR01 using the following code:

'Initialize variables Dim compObject, serverName serverName = "engsvr01" 'Get IIsWebServer object Set compObject = GetObject("IIS://" & serverName)

Note

A detailed discussion of scripting the metabase is beyond the scope of this book. If you want to learn Windows scripting, a good resource is the Windows 2000 Scripting Bible (John Wiley & Sons, 2000). Once you know how to program Windows scripts, use the IIS online help documentation to get a better understanding of what objects are available and how you can use them.

You can then work with any of the IIsComputer object’s methods and properties, such as these:

'Initialize variables Dim compObject, serverNameserver Name = "engsvr01" 'Get IIsWebServer object Set compObject = GetObject("IIS://" & serverName) 'Restore metabase config from last backup 'backup is stored in the default location compObject.Restore "MyBackup", MD_BACKUP_HIGHEST_VERSION, 0

You use the IIsWebServer object to set metabase properties that apply to a specific Web site and to set inheritable properties for directories and files. Methods are also available to control server operation. For example, you can use the Stop method to stop a site and then use the Start method to start the site.

Web sites are identified according to their index number in the metabase. The first Web site instance created on the server has an index number of 1, the second has an index of 2, and so on. The IIsWebServer object is an ADSI container object that has this AdsPath:

IIS://MachineName/W3SVC/N

where MachineName can be any computer name or LocalHost, W3SVC identifies the Web service, and N is the site’s index number. In the following example the AdsPath string specifies the first Web site instance on the server named ENGSVR01:

IIS://engsvr01/W3SVC/1

In VBScript, you can get the IIsWebServer object for the first Web site instance using the following code:

'Initialize variables Dim webObject, serverName, webN serverName = "engsvr01" webN = "1" 'Get IIsWebServer object Set webObject = GetObject("IIS://" & serverName & "/W3SVC/" & webN)

You can then work with any of the IIsWebServer object’s methods and properties, such as these:

'Initialize variables Dim webObject, serverName, webN serverName = "engsvr01" webN = "1" 'Get IIsWebServer object Set webObject = GetObject("IIS://" & serverName & "/W3SVC/"& webN) 'Stop Web site webObject.Stop 'Turn on ASP Buffering webObject.AspBufferingOn = True 'Save the changed value to the metabase webObject.SetInfo 'Start the Web server webObject.Start

You can use the IIsFtpServer object to set metabase properties that apply to a specific FTP server and to set inheritable metabase properties for directories. As with the IIsWebServer object, methods are also available to control server operation. You can, for example, call the Pause method to pause the FTP server and then call the Continue method to resume operation.

FTP servers are identified according to their index number in the metabase. The first server has an index number of 1, the second has an index of 2, and so on. The IIsFTPServer object is an ADSI container object that has this AdsPath:

IIS://MachineName/MSFTPSVC/N

where MachineName can be any computer name or LocalHost, MSFTPSVC identifies the FTP Service, and N is the server’s index number. In the following example the AdsPath string specifies the first FTP server on ENGSVR01:

IIS://engsvr01/MSFTPSVC/1

In VBScript you can get the IIsFtpServer object for the first FTP server instance using the following code:

'Initialize variables Dim ftpObj, serverName, ftpN serverName = "engsvr01" ftpN = "1" 'Get IIsFtpServer object Set ftpObj = GetObject("IIS://" & serverName & "/MSFTPSVC/" & ftpN)

You can then work with any of the IIsFtpServer object’s methods and properties, such as in the following:

'Initialize variables Dim ftpObj, serverName, ftpN serverName = "engsvr01" ftpN = "1" 'Get IIsFtpServer object Set ftpObj = GetObject("IIS://" & serverName & "/MSFTPSVC/"& ftpN) 'Stop FTP Server ftpObj.Stop 'Enable anonymous access ftpObj.AllowAnonymous = True 'Save the changed value to the metabase ftpObj.SetInfo 'Start FTP Server ftpObj.Start

Категории