
The introduction of Active Server Pages by Microsoft in Internet Information Server 3.0 was a significant event in the Internet server world. Prior to the advent of Active Server Pages, all server-side processing was performed using CGI. CGI, however, has two major limitations. The first is that most CGI scripts are written in PERL, which is difficult to learn and maintain. The second limitation is that the CGI program starts a separate instance for each user that is executing the CGI script. This imposes the overhead of loading and starting a separate instance for each use of the CGI script.
Active Server Pages can be written in VBScript, an easy-to-learn scripting language. There is no compiling, so maintenance is easy. Because the Active Server is a DLL that is part of the MS IIS service, all instances of the Active Server run in the same space, so there is no loading for each use. Active Server also interfaces to the ActiveX Data Objects for easy database usage. Active Server Pages is easy to use and create. Microsoft has created the Visual InterDev IDE that makes ASP development very simple, with many templates and wizards.
Dynamic Web content is the goal of all Web developers today. The first technology for providing dynamic content was CGI, but it was difficult and somewhat cumbersome. This was followed by Java applets, which are somewhat limited in their capabilities because of the requirement to stay in the sandbox. They also require a Java Virtual Machine.
These technologies were followed by JavaScript, ActiveX Controls, and VBScript. Except CGI, all of these required capability on the part of the browser. If the browser didn't support the technology, all of the work of the Web developer went for naught. All that the user saw was an ugly page that could not be understood.
Web browsers range in capability from LYNX, which is text only to Microsoft Internet Explorer, which supports almost all of the technologies employed on the Web today.The dilemma faced by the Web developer is attempting to determine the capabilities of the Web browsers in use by the client systems. This is less of an issue for intranet use where there is a better chance to impose some discipline on the browsers used.
As a result of these limitations, the creativity of the Web content remained restricted by the requirement to develop to the lowest common denominator of Web browser capability or by ignoring portions of the Web-browsing audience.
The ideal solution to this problem is to have dynamic Web content that relies only on the capabilities of the server and only serves HTML documents that are capable of being displayed by all Web browsers. The content should be easy to create and maintain, and the server should have the capability to access databases and display the information on all Web browsers.
Active Server Pages (ASP) is an ISAPI (Internet Server Application Program Interface) filter that looks at the extension for all files requested by clients from the server. When the extension is ASP, the Web page is handed to the Active Server.
The Active Server then reads the entire page and executes any server-side scripting and serves the resulting HTML page to the client system. This can be best understood by viewing a demonstration. Listing 54.1 is the contents of an Active Server Page.
<%@ LANGUAGE=îVBSCRIPTî %> <HTML> <HEAD> <META NAME=îGENERATORî Content=îMicrosoft Visual InterDev 1.0"> <META HTTP-EQUIV=îContent-Typeî content=îtext/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY BGCOLOR=White> <% for i = 1 to 7 %> <FONT SIZE=<% = i %>>ASP Demo Font Size <% = i %></FONT><BR> <% next %> </BODY> </HTML>
The page starts with the declaration of the scripting language as VBScript.
<%@ LANGUAGE="VBSCRIPT" %>
Notice that the script elements are enclosed in <% %> tags. This indicates to the Active Server that this is server-side script and should be executed. Variables can be included in lines of text. Figure 54.1 shows the page that is sent to the client browser, as displayed by Microsoft Internet Explorer 3.02.
This display looks virtually the same in any browser.
The HTML page sent by the Active Server is not the same as the page that was requested. The requested page contained VBScript. When you look at the contents of the page that was sent to the browser, as shown in Listing 54.2, you see that there is nothing but standard HTML. No special support is required by the browser to display this page.
<HTML> <HEAD> <META NAME=îGENERATORî Content=îMicrosoft Visual InterDev 1.0"> <META HTTP-EQUIV=îContent-Typeî content=îtext/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY BGCOLOR=White> <FONT SIZE=1>ASP Demo Font Size 1</FONT><BR> <FONT SIZE=2>ASP Demo Font Size 2</FONT><BR> <FONT SIZE=3>ASP Demo Font Size 3</FONT><BR> <FONT SIZE=4>ASP Demo Font Size 4</FONT><BR> <FONT SIZE=5>ASP Demo Font Size 5</FONT><BR> <FONT SIZE=6>ASP Demo Font Size 6</FONT><BR> <FONT SIZE=7>ASP Demo Font Size 7</FONT><BR> </BODY> </HTML>
The scripting language used to generate the HTML page does not need to be supported by the Web browser because all that the browser sees is the resulting HTML. Any text that is not controlled by the scripting language is included in the resulting page exactly as it is on the ASP file. Because the server encloses the server-side script in <% %> tags, client-side script can be included in the ASP file because it is enclosed in <SCRIPT> </SCRIPT> tags and will not be executed by the server.
This approach provides one other advantage over client-side scripting. The code that you have developed for use in the server-side script is not sent to the browser. Your code remains safely on your server where it cannot be copied by any user. This makes the investment of time and effort in developing Web content potentially more profitable because your techniques and code are not exposed to one and all for copying.
There are two scripting languages that are supported "out-of-the-box" by ASP: VBScript and JScript. JScript is the Microsoft implementation of JavaScript. The primary scripting language is declared as the first line of an ASP file:
<%@ LANGUAGE="VBSCRIPT" %>
This sets the primary scripting language to be VBScript. The following line sets it to be JScript:
<%@ LANGUAGE="JSCRIPT" %>
The script written in the primary scripting language is then enclosed in <% %> tags.
The scripting language can be changed in the same Active Server Page. If this is done, a script tag is inserted in the file with the language name parameter and the RUNAT="SERVER" parameter, as shown in the following code line:
<SCRIPT Language="JScript" RUNAT="Server">
The script tag </SCRIPT> must follow the end of the code block. Code from the primary script language and the secondary script language must not be intermingled within the same <SCRIPT> block.
When two script languages are used in the ASP file, the secondary language executes first followed by the primary language. Listing 54.3 shows an ASP file in which the primary and secondary scripting languages are alternated.
<%@ LANGUAGE=îVBSCRIPTî %> <HTML> <HEAD> <META NAME=îGENERATORî Content=îMicrosoft Visual InterDev 1.0"> <META HTTP-EQUIV=îContent-Typeî content=îtext/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY BGCOLOR=White> <% response.write (ìVBScript Print Line 1<br>î) %> <SCRIPT Language=îJScriptî RUNAT=îServerî> Response.Write (ëJavaScript Print Line 1<br>í); </script> <% response.write (ìVBScript Print Line 2<br>î) %> <SCRIPT Language=îJScriptî RUNAT=îServerî> Response.Write (ëJavaScript Print Line 2<br>í); </script> </BODY> </HTML>
In this demonstration, VBScript is set as the primary script language, and JScript is the secondary language. In Figure 54.2, you can see that the print lines generated by the JScript are both created first, and then the VBScript is executed.
The page as displayed by IE 3.02.
The HTML generated by the ASP file using two scripting languages is shown in Listing 54.4.
JavaScript Print Line 1<br>JavaScript Print Line 2<br> <HTML> <HEAD> <META NAME=îGENERATORî Content=îMicrosoft Visual InterDev 1.0"> <META HTTP-EQUIV=îContent-Typeî content=îtext/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY BGCOLOR=White> VBScript Print Line 1<br>VBScript Print Line 2<br> </BODY> </HTML>
Although two scripting languages can be used in one ASP file, you must carefully review the results to ensure the desired result.
Microsoft designed Active Server Pages to provide other scripting languages such as REXX, which is a widely used scripting language. It does not appear to be Microsoft's intention to add the support for other scripting languages but rather to make an open standard in which it is easy for others to add this support.
HTML forms collect information from a user for processing by the server. There are several Input objects that collect information and control the forms. The general form of the <INPUT> tag needs the TYPE parameter to be set to determine the Input object that will be created. There are other parameters depending on the type of the input element.
The HTML page shown in Listing 54.5 shows several of the input objects in a page. This page is shown as it is displayed in Figure 54.3. In the listing, notice that the form is within the <FORM>...</FORM> tag pair.
<HTML>
<HEAD>
<META NAME=îGENERATORî Content=îMicrosoft Developer Studioî>
<META HTTP-EQUIV=îContent-Typeî content=îtext/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY BGColor=white>
<CENTER>
Survey on Programming
<FORM ACTION=îFormDemoResponse.aspî METHOD=POST>
<TABLE>
<TR>
<TD>Logon</TD>
<TD><INPUT NAME=îTEXT_1" TYPE=TEXT SIZE=20></TD>
</TR>
<TR>
<TD>Password</TD>
<TD><INPUT TYPE=îPASSWORDî NAME=îTEXT_2" SIZE=20></TD>
</TR>
</TABLE>
Do you enjoy programming?<br>
<INPUT TYPE=îRADIOî NAME=îRADIO_1" VALUE=î0" CHECKED>Yes
<INPUT TYPE=îRADIOî NAME=îRADIO_1" VALUE=î1">No
<P>Comments
<BR><INPUT TYPE=îTEXTAREAî NAME=îTEXTAREA1" SIZE=î30,5" MAXLENGTH=î250">
<P><INPUT NAME=îCHECK1" TYPE=CHECKBOX CHECKED>Send the results of the survey.
<P><INPUT TYPE=îSUBMITî VALUE=îSubmitî><INPUT TYPE=îRESETî VALUE=îResetî>
</FORM>
</CENTER>
</BODY>
</HTML>
The Submit button must be within the <FORM>...</FORM> tag pair.
When the Submit button is clicked, the values in the objects are submitted to the Active Server Page shown in Listing 54.6. This form places three of the values in Input objects for display in the response form that is created by the ASP file. Figure 54.4 shows the page that the ASP file generates.
<CENTER>
<TABLE>
<TR>
<TD>Your Logon</TD>
<TD><INPUT NAME=îTEXT_1" TYPE=TEXT SIZE=20 VALUE=î<% = Request(ìTEXT_1î) Â%>î></TD>
</TR>
<TR>
<TD>Password</TD>
<TD><INPUT TYPE=îTEXTî NAME=îTEXT_2" SIZE=20 VALUE=î<% = Request(ìTEXT_2î) Â%>î></TD>
</TR>
</TABLE>
<P>Your Comments
<BR><INPUT TYPE=îTEXTAREAî NAME=îTEXTAREA1" SIZE=î30,5" MAXLENGTH=î250" ÂVALUE=î<% = Request(ìTEXTAREA1î) %>î>
</CENTER>
</BODY>
</HTML>
Active Server generates the response page.
As you have seen before, the page sent to the client browser is not the same as the ASP file. The page sent to the client is shown in Listing 54.7.
<HTML>
<HEAD>
<META NAME=îGENERATORî Content=îMicrosoft Visual InterDev 1.0">
<META HTTP-EQUIV=îContent-Typeî content=îtext/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY BGCOLOR=White>
<CENTER>
<TABLE>
<TR>
<TD>Your Logon</TD>
<TD><INPUT NAME=îTEXT_1" TYPE=TEXT SIZE=20 VALUE=îmylogonî></TD>
</TR>
<TR>
<TD>Password</TD>
<TD><INPUT TYPE=îTEXTî NAME=îTEXT_2" SIZE=20 VALUE=îmypasswordî></TD>
</TR>
</TABLE>
<P>Your Comments
<BR><INPUT TYPE=îTEXTAREAî NAME=îTEXTAREA1" SIZE=î30,5" MAXLENGTH=î250" ÂVALUE=îMy commentsî>
</CENTER>
</BODY>
</HTML>
The Active Server object Model is the key to understanding the power and flexibility of Active Server Pages. There are five server objects that solve many of the problems of working in the client server paradigm on the Web. These include tracking a user throughout a session and communication between users in an application.
Establishing an Active Server application involves creating a directory that is served by the Internet Information Server and has execute permissions. The naming convention for the files is name.ASP. The directory also contains one file named Global.ASA.
NOTE: Renaming a name.HTM file name.ASP does not create any problem. If the file does not contain any server-side scripting or components, Active Server simply transmits the file to the Web browser as is. Naming all files in an Active Server application name.ASP is advantageous because it ensures that the Active Server ISAPI filter will intercept the file and deals properly with the Application and Session objects.
Global.ASA. The Global.ASA file can contain scripts that run at four specific events. The first event is the start of an application, which is defined as the first time that a page from an application is requested and the first user session is started. This is the Application_OnStart event. The second is the Application_OnEnd event. This fires when there are no user sessions, and the last session times out or is closed.
The Session_OnStart event fires when a user first establishes a session with the application. A SessionId is also generated that is a long integer that is unique within the time between the Application_OnStart and Application_OnEnd. It is not, however, a unique user ID that can be used across sessions. This SessionID is used in a cookie that is sent to the browser and can be used to track the user session. Listing 54.8 shows a sample Global.ASA file and indicates where the script can be entered.
<SCRIPT LANGUAGE=îVBScriptî RUNAT=îServerî> Sub Application_OnStart ë**Put your code here ** End Sub </SCRIPT> <SCRIPT LANGUAGE=îVBScriptî RUNAT=îServerî> Sub Application_OnEnd ë**Put your code here ** End Sub </SCRIPT> <SCRIPT LANGUAGE=îVBScriptî RUNAT=îServerî> Sub Session_OnStart ë**Put your code here ** End Sub </SCRIPT> <SCRIPT LANGUAGE=îVBScriptî RUNAT=îServerî> Sub Session_OnEnd ë**Put your code here ** End Sub </SCRIPT>
Some uses of the Global.ASA file include creating database connections and cleaning up after a user and when the application closes.
NOTE: Cookies are a piece of data that is sent to the browser and written on the user's hard drive. Each cookie contains the identity of the domain that sent the cookie. This cookie is returned to the server when a request is sent to the same domain. Cookies can contain information that is to be retained between requests and sessions. A cookie can also have an expiration.
CAUTION: Cookies have received a lot of press lately. Most browsers can refuse cookies, so the use of cookies might not be available to all users.
Execute Permissions. The directory that contains ASP files and Global.ASA files must have execute permission set for the anonymous user that is used by the IIS server for Web access.
The Application object has two events, the Application_OnStart and Application_OnEnd events, used to initiate the processing of a script in the Global.ASA file. The script can perform tasks that might be needed at the beginning of an application, such as creating a connection to a database and closing the connection at the end of the session. It can also initialize user counter and messages.
You can store values in the Application object. Information stored in the Application object is available throughout the application and has application scope. The following stores a variable in the Application object:
Application("greeting") = "Welcome to My Web World!"
To store an object in the Application object and use VBScript as your primary scripting language, use the Set keyword as shown:
<% Set Application("Obj1") = Server.CreateObject("MyComponent") %>
The Application object has two methods, the Lock method and the Unlock method. The Lock method prevents other clients from modifying Application object properties while they are being set by a client. The Unlock method enables other clients to modify Application object properties. The Lock and Unlock prevent a collision between two users attempting to modify the value of an Application property at the same time. If a client finds the Application property locked, it is required to wait until the Unlock method removes the lock.
The Session object has two events: Session_OnStart and Session_OnEnd. These are used to initiate the processing of a script in the Global.ASA file. The script can perform tasks that might be needed at the beginning of a session, such as updating a user counter. It can also initialize session settings.
You can store values in the Session object. Information stored in the Session object is available throughout the session and has session scope. The following line stores a variable in the Session object:
Session("username") = "Jennifer"
If you store an object in the Session object and use VBScript as your primary scripting language, use the Set keyword, as shown:
<% Set Session("Obj1") = Server.CreateObject("MyComponent") %>
The Session object has two properties: the SessionId and the Timeout. The SessionId is a number assigned by Active Server when the user session starts. The SessionID is a long integer that is unique throughout the time between the Application_OnStart and Application_OnEnd events. It is not a GUID (Globally Unique Identifier) and should not be used as such. The SessionId is passed to and returned by the browser to track a user session.
The Timeout property is the time in minutes that a session stays open with no activity. The default is 20 minutes.
The Session object has one method, the Abandon method. When this method is called on a session, the session is discontinued and all Session objects are destroyed. If the user makes a subsequent request, a new session is started.
The Request object contains the values that the browser passed with the request for a file. These values are contained in collections.
The ClientCertificate Collection. This collection retrieves the certification fields from the request that the Web browser issued. These are the fields specified in the X.509 standard.
If a Web browser uses the Secure Sockets Layer protocol https:// to connect to the server, and the server requests certification, the browser sends the certification fields. Before you can use the ClientCertificate collection, however, you must configure your Web server to request client certificates.
The Cookies Collection. This collection contains the values of the cookies sent in an HTTP request. The syntax is:
Request.Cookies(cookie)[(key)|.attribute]
The cookie parameter specifies the cookie whose value should be retrieved. The key parameter is an optional parameter used to retrieve subkey values from cookie dictionaries. The attribute parameter specifies information about the cookie itself. The attribute parameter can be Name, Description, or HasKeys. You can access the subkeys of a cookie dictionary by including a value for a key. If the cookie dictionary is accessed without specifying a key, all of the keys are returned as a single query string.
The Form Collection. This collection contains the values of form elements posted to the HTTP request body by a form using the POST method. These values can be referred to by the collection index or the element name. For example if the Input object on the request form is named "MyTextBox," the value can be referred to as Request.Form("MyTextBox").
NOTE: The collection names do not need to be included in the reference to the Request object. For example, a reference to Request.Form("MyVar") can be Request("MyVar").
The QueryString Collection. This collection contains the values of the variables of an HTTP query string. These are the values encoded after the question mark (?) in an HTTP request.
The QueryString collection is a parsed version of the QUERY_STRING variable in the ServerVariables collection. You are able to retrieve the QUERY_STRING variables by name. The value of Request.QueryString(parameter) is an array of all of the values of parameters that occur in QUERY_STRING.
The ServerVariables Collection. This collection contains the values of the environment variables. The syntax to refer to ServerVariables is:
Request.ServerVariables (variable)
The variables are:
The list of recognized header names is:
This object is the most complex of the Active Server objects. It is used to send output to the client. The Response object has one collection, five properties, and eight methods.
The Cookies Collection. This collection sets the value of a cookie. If the cookie does not exist, it will be created. If the cookie exists, the new value replaces the old value. The syntax is:
Response.Cookies(cookie)[(key)|.attribute] = value
The key is an optional parameter. When a key is specified, the cookie is a dictionary, and the key is set to a value. There are several attributes that can be set for a cookie which include the expiration of the cookie.
Listing 54.9 shows a cookie being created with two keys. Notice that the cookie is created before any other functions are performed in the page.
<%@ LANGUAGE=îVBSCRIPTî %> <% Response.Cookies(ìMycookieî)(ìType1î) = ìValue1î Response.Cookies(ìMycookieî)(ìType2î) = ìValue2î %> <HTML> <HEAD> <META NAME=îGENERATORî Content=îMicrosoft Visual InterDev 1.0"> <META HTTP-EQUIV=îContent-Typeî content=îtext/html; charset=iso-8859-1"> <TITLE>Document Title</TITLE> </HEAD> <BODY BGCOLOR=White> Hello, this creates a Cookie. </BODY> </HTML>
The header sent to the browser that contains the Cookies is:
Set-Cookie:MYCOOKIES=TYPE1=Value1&TYPE2=Value2
The Buffer Property. This property indicates whether to buffer page output or not. When page output is buffered, the server does not send a response to the client until all of the server scripts on the current page are processed or until the Flush or End method has been called. The syntax:
Response.Buffer [= True|False]
should be the first line in the ASP file because the property can't be set after any content has been sent to the client.
The ContentType Property. This property specifies the HTTP content type for the response. The default is "text/HTML." Examples of other types are "image/GIF" and "text/plain." An example of the syntax is:
Response.ContentType = "text/HTML"
The Expires Property. The length of time before a page cached on a browser expires is set by the Expires property. The cached version of the page is displayed if the user returns to the same page before it expires. The property value sets the time in minutes. A setting of 0 causes the cached page to expire immediately. The syntax is:
Response.Expires [= number]
The ExpiresAbsolute Property. The date and time at which a page cached on a browser expires is set in the ExpiresAbsolute property. If the user returns to the same page before that date and time, the cached version is displayed. If a time is not specified, the page expires at midnight of that day. If a date is not specified, the page expires at the given time on the day that the script is run.
cResponse.ExpiresAbsolute [= [date] [time]]
The Status Property. The Status property specifies the value of the status line returned by the server. A status of 200 indicates success. The status values are defined in the HTTP specification. This is the source of the "HTTP/1.0 404 Object Not Found." The syntax is:
Response.Status = StatusDescription
The AddHeader Method. An HTML header with a specified value is added by using the AddHeader method, which always adds a new HTTP header to the response. It will not replace an existing header of the same name, and after a header has been added, it cannot be removed. If another Response method provides the functionality you require, it is suggested that you use that method instead. The syntax is:
Response.AddHeader name, value
The AppendToLog Method. To add a string to the end of the Web server log entry for this request, use the AppendToLog method. You can call this method multiple times in one section of a script. Each time the method is called it appends the specified string to the existing entry. Because fields in the Internet Information Server log are comma-delimited, this string cannot contain any comma characters (,). The maximum length of this string is 80 characters. The syntax is:
Response.AppendToLog string
The BinaryWrite Method. To write information to the current HTTP output without any character conversion, use the BinaryWrite method. This method writes nonstring information, such as binary data required by a custom application, such as an image processor. The syntax is:
Response.BinaryWrite data
The Clear Method. This method erases any buffered HTML output. The Clear method only erases the response body. It does not erase response headers. This method can be used to handle errors and will cause a runtime error if Response.Buffer is not set to TRUE. The syntax is:
Response.Clear
The End Method. This method stops processing by the Web server on the script and returns the current result. The remaining contents of the file are not processed. If Response.Buffer has been set to TRUE, calling Response.End flushes the buffer. If you do not want output returned to the user, call the Clear method first. The syntax is:
Response.End
The Flush Method. This method sends buffered output immediately and causes a runtime error if Response.Buffer has not been set to TRUE. If the Flush method is called on an ASP page, the server does not honor Keep-Alive requests for that page. The syntax is:
Response.Flush
The Redirect Method. When the Redirect method is called, the browser attempts to connect to a different URL. Ths syntax is:
Response.Redirect URL
The Write Method. To write a specified string to the current HTTP output, use the Write method. The variant parameter can be any data type supported by the Visual Basic® Scripting Edition VARIANT data type, including characters, strings, and integers. The syntax is:
Response.Write variant
The Server object is very useful. Most of its methods and properties work as utility functions. The Server object has one property and four methods.
The ScriptTimeout Property. This property specifies the maximum amount of time a script can run before it is terminated in seconds. The default value is 90 seconds. The ScriptTimeout property cannot be set to a value less than that specified in the registry settings. If NumSeconds is set to 10, and the registry setting contains the default value of 90 seconds, scripts time out after 90 seconds. If NumSeconds is set to 120, the scripts time out after 120 seconds. The syntax is:
Server.ScriptTimeout = NumSeconds
The CreateObject Method. This method creates an instance of a server component, discussed in the section "Active Server Components." The syntax is:
Server.CreateObject( progID )
The HTMLEncode Method. This method applies HTML encoding to a specified string. This is used to display HTML symbols in an HTML page. As an example:
<%= Server.HTMLEncode("The paragraph tag: <P>") %>
produces the output:
The paragraph tag: <P>
which will be displayed as:
The paragraph tag: <P>
The syntax is:
Server.HTMLEncode( string )
The MapPath Method. This method maps the specified relative or virtual path to the corresponding physical directory on the server. The path parameter specifies the relative or virtual path to map to a physical directory. If the path starts with either a forward or backward slash, either (/) or (\), the MapPath method returns a path as if the path is a full virtual path. If the path doesn't start with a slash, the MapPath method returns a path relative to the directory of the ASP file being processed. The MapPath method does not check whether the path it returns is valid or exists on the server. The syntax is:
Server.MapPath( path )
The URLEncode Method. This method applies URL encoding rules, including escape characters, to a specified string. The following example script:
<%= Server.URLEncode("The paragraph tag: <P>") %>
produces the output:
The+paragraph+tag%3A+%3CP%3E
The syntax is:
Server.URLEncode( string )
Active Server includes five built-in Active Server components:
Listing 54.10 shows the ASP file that is used to create an instance of the Ad Rotator component.
<%@ LANGUAGE=îVBSCRIPTî %> <HTML> <HEAD><TITLE>VBScript Using the Ad Rotator</TITLE></HEAD> <BODY BGCOLOR=#FFFFFF> <H3>VBScript Using the Ad Rotator</H3> <% Set Ad = Server.CreateObject(ìMSWC.Adrotatorî) %> <%= Ad.GetAdvertisement(ì/ASPSamp/Samples/adrot.txtî) %> <BR> <BR> </BODY> </HTML>
The line
<% Set Ad = Server.CreateObject("MSWC.Adrotator") %>
creates the Ad Rotator object. The line
<%= Ad.GetAdvertisement("/ASPSamp/Samples/adrot.txt") %>
retrieves the information from the Adrot.txt file, which holds the parameters for the Ad Rotator component. Listing 54.11 shows the contents of this file.
redirect /AdvWorks/adredir.asp width 460 height 60 border 1 * /AdvWorks/multimedia/images/ad_1.gif http://www.microsoft.com Astro Mt. Bike Company 20 /AdvWorks/multimedia/images/ad_2.gif http://www.microsoft.com Arbor Shoes 20 /AdvWorks/multimedia/images/ad_3.gif http://www.microsoft.com Clocktower Sporting Goods 30 /AdvWorks/multimedia/images/ad_4.gif http://www.microsoft.com GG&G 30
The Ad Rotator works this way: Each time the same user returns to the page with the Ad Rotator component, a different ad is shown.
© Copyright, Macmillan Computer Publishing. All rights reserved.