The Object Model for IIS Applications

See Also

IIS applications are hosted by an .asp (Active Server Pages) file and make use of several of the objects in the Active Server Pages object model. The webclass uses these objects to access and manipulate information from an HTML page. The ASP objects that a webclass can use include:

The ASP Request Object

You use the Request object to retrieve information from or about the current user. The Request object gives you access to all of the information passed in any HTTP request. HTTP requests contain information about the current user, any data they entered prior to making the request, and arguments that tell the Web server how to process and respond to the request.

Most frequently, you use the Request object to retrieve information from an HTML form. For example, you might retrieve all of the form elements passed back in a Submit event. The following example shows how you might use the Request object to gather information from the browser:

Private Sub Webitem1_Submit
   'Define variables to hold information retrieved from the request
   Dim first as String
   Dim last as String
   'Retrieve form information and assign it to the variables, using
   'the Request object and its Form collection.
   First = Request.Form("Firstname")
   Last = Request.Form("Lastname")
End Sub

You can use the Request object's associated collections to access information. These collections include:

For More Information   See "Getting Information from a User" in the Active Server Pages Scripting Guide for more information on the Request object and its collections.

The ASP Response Object

You use the Response object to return information to the browser. For example, you might use the object's Respond event to write HTML to the browser. There are several methods you can use with the Response object:

The following example shows how you might use the Response object to write a few lines of HTML code to the browser:

With Response
   'Indicate the beginning of the HTML page
   .Write "<HTML>"
   'Indicate the beginning of the body section
   .Write "<BODY>"
   'Send a line with heading two style followed by
   'a paragraph break
   .Write "<H2>Feedback Form</H2><P>"
   'Send a paragraph of text
   .Write "Please enter your comments below:<P>"
   'other write statements to present form elements 
   'and close the HTML document.
End With

For More Information   See "Sending Information to a User" in the Active Server Pages Scripting Guide for more information on the Response object and its collections.

The ASP Session and Application Objects

The Session and Application objects both store state information about the webclass's end users. The Session object can store information about a single user in the current session. The Application object can store information about multiple users.

You use the Session object to maintain information about the current user session and to store and retrieve state information. For example, suppose you have an application that uses two main pages: one that summarizes customer information, and one that allows the user to order products. You want to ensure that the customer only sees the information page once, regardless of how many transactions they enter. In order to do this, the webclass must be able to determine whether the user has seen the customer information when it processes each new order. You can do this by using the Session object to retain information about where the user has already been.

You use the Application object to store information about multiple users. For example, suppose you want to keep track of the number of users who access a webclass and access that statistic online. You can do this by storing a count in the Application object and incrementing it each time a user accesses a part of the webclass.

For More Information   See "State Management in IIS Applications" for a code example of storing state in the Session and Application objects.

The ASP Server Object

You use the Server object to create objects and determine server-specific properties that might influence the webclass's processing. For example, suppose you have a library of business objects that are used during event processing. One of these objects must be kept alive throughout the session in order to maintain internal state. You can do this using the Server and Session objects.

In this case, you could choose to store the object as a Session property, using Server.CreateObject to create an instance of it. This is necessary so that IIS can detect the threading model of the object and optimize subsequent request processing.

The following code shows how you would do this in your event procedure:

Dim BusObj as SomeBusinessObject
Set BusObj = Server.CreateObject("OurCompany.SomeBusinessObject.1")
'Code here to call methods of the object
Set Session("BusObjInstance") = BusObj

The ASP BrowserType Object

You use the BrowserType object to determine the capabilities of the user's browser and make processing decisions based on that information. For example, suppose you have an application that contains a button called CheckInventory. This button allows the user to check available inventory before placing an order. You provide two versions of the event procedure for this button in your webclass — one using HTML and one using JavaScript. You might do this if the JavaScript procedure provides a better user experience — for example, it might not cause a page transition, where the HTML procedure would.

In this scenario, you could use the BrowserType object to determine which procedure to use by determining if the user's browser supports JavaScript. The following code shows how you would use the BrowserType object to make this choice:

Private Sub OrderForm_ProcessTag(ByVal TagName As String, TagContents As String, SendTags as Boolean)

   'If the browser supports Javascript, generate HTML to call 
   'a method on an applet. If it does not, generate HTML to 
   'fire an event on the webclass.
   
   If TagName = "WC@FORMTAGSTART" Then
      If BrowserType.javascript And BrowserType.javaapplets Then
         TagContents = "<FORM onsubmit=""JavaScriptHandler()"">"
      Else
         TagContents = "<FORM ACTION=" & URLFor(OrderForm _
         "OrderForm_Submit") & " METHOD=POST>"
      End If
   End If
   SendTags = False
End Sub