Microsoft KB Archive/221505

= HOWTO: Using the AspAppRestart Method in IIS 5.0 =

Article ID: Q221505

The information in this article applies to:


 * Microsoft Internet Information Server version 5.0

SUMMARY
Microsoft's Internet Information Services (IIS) version 5.0 for the Windows 2000 family supports a new ADSI method titled "AspAppRestart," which allows Web developers to restart an application through Active Server Pages (ASP) code.

MORE INFORMATION
The following steps illustrate a simple example to restart an application when a counter stored in an application variable has been incremented five times.

1. First, create an application from your default "scripts" virtual directory:

a. Open up your server in the MMC.

b. Expand your default Web site.

c. Right-click on your Scripts virtual folder.

d. Select Properties.

e. Select the Virtual Directory tab.

f. Click the Create button.

g. Click the OK button.

h. Close the MMC. 2. Next, save the following code in your Scripts folder as Global.asa:

 Sub Application_OnStart Application("Count") = 1 End Sub 3. Next, save the following page as Restart.asp in your Sscripts folder:

<% @Language="VBSCRIPT" %> <%    ' NOTE - the following lines force authentication, ' since anonymous access cannot restart an application If Request.ServerVariables("LOGON_USER") = "" Then Response.Clear Response.Status = "401 Access Denied" Response.End End If  %> The count is <%=Application("Count")%> <%    If (Application("Count") Mod 5) Then Application("Count") = Application("Count") + 1 Else Set srvObj = GetObject("IIS://localhost/w3svc/1/root/scripts") srvObj.AspAppRestart Response.Write " - Restarted" End If  %> 4. Browse to this page. You will see that the count starts at 1. If you refresh

this page, you will see that the count increases by one. Once the this count reaches five, the application will be restarted and the count will be reset to 1.