Improvements to the ASP Programming Environment

Applies To: Windows Server 2003, Windows Server 2003 with SP1

In IIS 6.0, you can make use of the following enhancements to the ASP programming environment:

  • Improved international and UTF-8 support. UTF-8 support has been expanded to include all ASP built-in object properties and methods. The previous version of ASP supported UTF-8 only for Response.Write.

  • Improved POST support. ASP can now read chunked-encoded POST data from a client.

  • UNC enhancements. If your ASP scripts reside on a Universal Naming Convention (UNC) share, ASP has improved performance in executing those scripts. For information about configuring IIS 6.0 with remotely stored content on UNC servers, see Deploying and Configuring Internet Information Services (IIS) 6.0 with Remotely Stored Content on UNC Servers and NAS Devices.

  • Optional script source access in ASP pages. Script source access, which allows access to the source code of scripts in ASP pages and other scripts, is new and is disabled by default. To enable script source access, you must select either Read or Write permission.

  • COM+ services in ASP. You can now configure your ASP applications to use the following COM+ services without having to create a COM component:

    • Apartment model selection

    • Side-by-side assemblies

    • COM+ partitions

    • COM+ tracker

COM+ Services in ASP

In previous versions of IIS, if you wanted to use COM+ services from an ASP application, you had to create a COM component to call the methods of those services. In IIS 6.0, COM+ services are separate from the components. This separation allows ASP applications to use a set of COM+ services without instantiation by any COM components. Because of this separation, you can configure your ASP application to use the following COM+ services without having to create a COM component.

Note

Batch Logon is required for COM+ server-activated application identities. COM+ will add this automatically when you enter a new account for the identity of a COM+ application using the UI. Batch Logon gives your application the ability to execute code across servers, but does not allow the account to logon interactively to home server.

Since only side-by-side assemblies can be enabled using IIS Manager, example code for enabling each service on an ASP application is provided below.

This topic includes the following information:

  • Apartment Model Selection

  • Side-by-Side Assemblies

  • COM+ Partitions

  • COM+ Tracker

Apartment model selection

ASP is now capable of running all of its threads in a multithreaded apartment (MTA). If your COM components are primarily free-threaded or both-threaded, running the ASP threads as MTA can improve performance significantly.

To enable an ASP application to run in an MTA, set the AspExecuteInMTA metabase property at the application level. This enables you to have one application running on ASP MTA threads and a second application running on ASP single-threaded apartment (STA) threads. By default, ASP runs applications in the STA.

Important

When you switch an ASP application from running in STA to MTA (or from MTA to STA), the impersonation token becomes obsolete, which can cause the application to run with no impersonation. Without impersonation, the application runs with the identity of the process, which might allow access to other resources. If you must switch threading models, disable and unload the application before you make the change.

The following example sets the Default Web Site application (W3SVC/1/ROOT) to execute in MTA:

On Error Resume Next
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2")
' Get a reference to the ASP application called Default Web Site
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "Before: AspExecuteInMTA = " & IIsWebVirtualDirSettingObj.AspExecuteInMTA
' Set the ASP application to execute in MTA
IIsWebVirtualDirSettingObj.AspExecuteInMTA = 1
IIsWebVirtualDirSettingObj.Put_()
WScript.Echo "After: AspExecuteInMTA = " & IIsWebVirtualDirSettingObj.AspExecuteInMTA

Side-by-side assemblies

Side-by-side (SxS, in metabase property names) assemblies allow ASP applications to specify which version of a system DLL or shared COM component to use. For example, if your ASP application relies on MSXML version 2.0, you can ensure that your application still uses MSXML 2.0 even if a later version is installed on the computer for use by other applications.

Configuring SxS assemblies requires that you know the path to the DLL, and that the COM+ manifest file exists in every virtual directory that requires the use of the DLL. The COM+ manifest is an XML file that contains information about where a DLL is installed. IIS does not verify that the manifest exists. A manifest looks like the following file excerpt:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity publicKeyToken="75e377300ab7b886" type="win32" name="Test4Dir" version="1.0.0.0" processorArchitecture="x86"/>
<file name="DirComp.dll" hash="35ca6f27b11ed948ac6e50b75566355f0991d5d9" hashalg="SHA1">
<comClass clsid="{6C6CC20E-0F85-49C0-A14D-D09102BD7CDC}" progid="DirComp.PathInfo" threadingModel="apartment"/>
<typelib tlbid="{AA56D6B8-9ADB-415D-9E10-16DD68447319}" version="1.0" helpdir=""/>
</file>
</assembly>

You can enable side-by-side assemblies either programmatically or by using IIS Manager. To programmatically enable side-by-side assemblies, set the AspEnableSxs flag of the AspAppServiceFlags metabase property to true. Also, set the AspSxsName metabase property to the name of the COM+ manifest. Set both metabase properties at the application level.

Important

Even though this feature is configurable at the application level, you must not use more than one version of a system DLL in any IIS6.0 application pool. If you load more than one version of a system DLL in an application pool, the application that is loaded first has its version loaded and the other applications are forced to use that DLL until the applications are unloaded.

The following example enables side-by-side assemblies on the Default Web Site application (W3SVC/1/ROOT). Notice that after setting only the AspEnableTracker property, the AspAppServiceFlags property changes as well:

On Error Resume Next
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2")
' Get a reference to the ASP application called Default Web Site
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "Before: AspEnableSxs = " & IIsWebVirtualDirSettingObj.AspEnableSxs
WScript.Echo "        AspSxsName = " & IIsWebVirtualDirSettingObj.AspSxsName
WScript.Echo "        AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
' Set the ASP application to enable COM+ side-by-side assemblies
IIsWebVirtualDirSettingObj.AspEnableSxs = 1
' Set the AspSxsName property
IIsWebVirtualDirSettingObj.AspSxsName = "VersionInfo"
' Save the values to the IIS metabase
IIsWebVirtualDirSettingObj.Put_()
' Get the reference again in order to refresh the AspAppServiceFlags property.
set IIsWebVirtualDirSettingObj = Nothing
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "After: AspEnableSxs = " & IIsWebVirtualDirSettingObj.AspEnableSxs
WScript.Echo "       AspSxsName = " & IIsWebVirtualDirSettingObj.AspSxsName
WScript.Echo "       AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags

COM+ partitions

You can use COM+ partitions to isolate Web applications in their own COM+ partitions. Isolation is useful to prevent one Web application from accessing the private COM+ applications, configuration information, and data of another Web application.

COM+ partitions can hold different versions of your own custom COM components. For example, if you host Web sites for two competing companies that both use COM+ in their Web applications, you can use COM+ partitions to ensure that one company's Web application cannot access the COM+ components in the other company's Web applications. If one of those companies asks you to change certain features in a COM+ application that both companies use, you can isolate the new version of that COM+ application in the partition that is linked to that company's Web application.

To enable COM+ partitions in IIS, set the AspUsePartition flag of the AspAppServiceFlags metabase property at the application level. The partition is identified by a globally unique identifier (GUID) (created by using the Component Services Manager snap-in), which is set by the AspPartitionID metabase property. If no partition is specified, the default system partition is used. For more information, please see "Creating and Configuring COM+ Partitions" in the COM+ SDK or online at COM+ (Component Services).

Important

Even though you can configure this feature at the application level, use only one version of a COM+ component in any application pool. For example, if application App1 uses version1.0 of a custom COM+ application called Shop.dll, and application App2 uses version2.0 of Shop.dll, App1 and App2 cannot be in the same application pool. If you put them in the same application pool, the application that you load first has its version of Shop.dll loaded, and the other application is forced to use that version until the applications are unloaded.

The following example enables partitions on the Default Web Site application (W3SVC/1/ROOT). Notice that after setting only the AspEnableTracker property, the AspAppServiceFlags property changes as well.

On Error Resume Next
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2")
' Get a reference to the ASP application called Default Web Site
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "Before: AspUsePartition = " & IIsWebVirtualDirSettingObj.AspUsePartition
WScript.Echo "        AspPartitionID = " & IIsWebVirtualDirSettingObj.AspPartitionID
WScript.Echo "        AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
' Set the ASP application to enable COM+ partitioning
IIsWebVirtualDirSettingObj.AspUsePartition = 1
' Set the AspPartitionID property to the GUID configured in Component Services Manager
' when you created the COM+ partition
IIsWebVirtualDirSettingObj.AspPartitionID = "{00000000-0000-0000-0000-000000000000}"
' Save the values to the IIS metabase
IIsWebVirtualDirSettingObj.Put_()
' Get the reference again in order to refresh the AspAppServiceFlags property.
set IIsWebVirtualDirSettingObj = Nothing
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "After: AspUsePartition = " & IIsWebVirtualDirSettingObj.AspUsePartition
WScript.Echo "       AspPartitionID = " & IIsWebVirtualDirSettingObj.AspPartitionID
WScript.Echo "       AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags

COM+ tracker

COM+ tracker allows you to debug ASP applications. For example, if you need to diagnose and fix a faulty Web application, you can enable COM+ tracker to determine when ASP pages are being loaded, when COM components are loaded, and when threads leave a page. After debugging your application, you can disable COM+ tracker to return your application to normal performance speed.

To enable COM+ tracker on the IIS side, set the AspEnableTracker flag of the AspAppServiceFlags metabase property at the application level.

The following example enables tracking on the Default Web Site application (W3SVC/1/ROOT). Notice that after setting only the AspEnableTracker property, the AspAppServiceFlags property changes as well:

On Error Resume Next
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2")
' Get a reference to the ASP application called Default Web Site
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "Before: AspEnableTracker = " & IIsWebVirtualDirSettingObj.AspEnableTracker
WScript.Echo "        AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
' Set the ASP application to enable COM+ tracking
IIsWebVirtualDirSettingObj.AspEnableTracker = 1
IIsWebVirtualDirSettingObj.Put_()
' Get the reference again in order to refresh the AspAppServiceFlags property.
set IIsWebVirtualDirSettingObj = Nothing
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "After: AspEnableTracker = " & IIsWebVirtualDirSettingObj.AspEnableTracker
WScript.Echo "       AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags

For more information about these enhancements to COM+ services in ASP, including application examples of each, see What's New in ASP.

New Metabase Properties for ASP

Table 3.9 describes the metabase properties for ASP that are new in IIS 6.0.

Table 3.9   New ASP Metabase Properties in IIS 6.0

Property Purpose

AspAppServiceFlags

Contains the flags that must be set to enable COM+ services on your IIS applications.

AspDiskTemplateCacheDirectory

Specifies the location of the ASP disk cache.

AspExecuteInMTA

Enables ASP threads to execute in an MTA.

AspKeepSessionIDSecure

Sends the ASP session cookie to a browser securely.

AspMaxDiskTemplateCacheFiles

Specifies the maximum number of compiled ASP templates that can be stored.

AspPartitionID

Sets the COM+ partition to use for the application.

AspRunOnEndAnonymously

Enables ASP to run the Global.asa Application_OnEnd and Session_OnEnd events anonymously.

AspBufferingLimit

Specifies the buffer size limit.

AspMaxRequestEntityAllowed

Specifies the maximum number of bytes allowed in the entity body of an ASP request.

AspSxsName

Allows ASP applications to specify which version of a system DLL or COM component to use.

For more information about how to use these new metabase properties, see the Metabase Property Reference.