Using Active Server Pages with Microsoft Internet Information Server 3.0

Microsoft Corporation

November 1996

Contents

Abstract
Introduction
Active Server Pages
Scripting and Active Server Pages
ActiveX Components
Active Server Page Applications
Summary

Abstract

Microsoft® Internet Information Server (IIS) version 3.0 introduces Active Server Pages, the technology formerly code-named "Denali." Active Server Pages (.asp files) let organizations easily combine ActiveX™ scripts and ActiveX components to create dynamic content and powerful Web-based applications.

Active Server Pages enable component-based Web application development in any language, including Sun Microsystems Java™. It is easy to learn, it provides an open development environment, and it allows developers to build truly browser-independent Web solutions.

The combination of .asp files in IIS 3.0 running on Microsoft Windows NT® Server version 4.0 provides the ideal platform for developing personalized content and powerful Web-based business solutions for corporate intranets and the Internet.

Introduction

Organizations are looking to Internet technology to improve productivity, reduce costs, and provide access to existing information and knowledge in new, dynamic, and interactive ways. Businesses want to run Web-based applications on their servers in order to realize the advantages of providing users access to "information at their fingertips." For example you can:

While much of this can be done today through creative programming tricks, the challenge until now has been to find a technology that is easy to use, open, and scaleable and takes advantage of existing skills and investments.

Microsoft IIS 3.0 was designed to be a powerful, open platform for developing Internet and corporate intranet applications with .asp files. IS professionals and Webmasters can combine ActiveX scripts with ActiveX components running on the server to create a new generation of server-based solutions for the Web.

This whitepaper is designed to provide a detailed overview of the various building blocks that Active Server Pages make available to Web developers. These include the following:

active Server Pages

IIS 3.0 introduces Active Server Pages, which enable Hypertext Markup Language (HTML) authors and Web developers to mix HTML and inline scripting using almost any authoring tool. The scripts can reference components running on the local server—or any other server—to access databases, applications, or process information. When a browser requests an .asp file, it is processed by the server and the page is returned to the client as standard HTML.

Open

When using IIS 3.0, developers are not required to use a proprietary scripting language to create Web applications—Active Server Pages are compatible with any ActiveX Scripting language. Active Server Pages include native support for Microsoft Visual Basic® Scripting Language (VBScript) and Microsoft Jscript™. Third parties will be providing support, through plug-ins, for other languages such as REXX, Perl, and Tcl. Multiple-scripting languages can even be used interchangeably in the same .asp file.

ActiveX components can be created in virtually any language. This includes Java, Visual Basic, C++, and COBOL.

Approachable

Active Server Pages make it easy for HTML authors to "activate" their Web pages on the server. Customized pages and simple applications can be developed immediately. Instead of writing complicated Common Gateway Interface (CGI) programs in languages such as Perl and C to generate personalized content for each user, a Web developer can use an Active Server Page to do all the work. In the following simple example, VBScript is used to display both the current time and the type of browser the client is using. The following example shows HTML with inline VBScript:

<HTML>
<HEAD>
<TITLE>Sample Web Page</TITLE>
</HEAD>
<BODY>
<P>
Hello <%= Request.ServerVariables("REMOTE_USER") %>
The time here is <%= now %>
Your browser is <% = Request.ServerVariables("http_user_agent") %>
</BODY></HTML>

Separating Content and Logic from Presentation

The Web brings together teams from many disciplines—graphic arts, HTML authoring, programming, publishing, and more. The challenge is to enable them to work together efficiently and to make changes without upsetting each others work. Dynamic content today often requires elements of design, logic, and content to live together. This makes Web development difficult as changes require wading through lines of Perl or C code, and an inadvertent change could damage the program or the HTML formatting.

Through the use of scripting and components, Active Server Pages allow you to separate the programming that accesses data in databases and applications from the design and other content of a Web page. This helps to ensure that developers can be free to focus on writing their business logic in components without worrying about how the output appears. Conversely, it frees HTML designers to use familiar tools to modify the page as they see fit. Scripting is the "glue" that ties them together.

In the example below, a form is used to pass a ticker symbol request from the Uniform Resource Locator (URL) to the .asp files. The first part of the .asp file calls a component that contacts a stock price server. Properties of this object, such as opening and closing price, can then be easily inserted in the HTML. The programmer can work in any language and only needs to worry about communication with the stock price server. The HTML author only needs to know how to script the component and does not care how the stock price server works.

First, the user request is received:

<HTML>
<% 
   TSym=Request.QueryString("TickerSymbol")

Then, the component is invoked:

   Set NObj=Server.CreateObject("NASDAQ.TickerObj") 
   if NObj.GetCompany(TSym)=False then
       Server.Redirect("ticker/entryform.htm")
%>

And finally, the dynamic content is inserted:

<H1>Today's trade summary for:<%=NObj.CompanyName%> </H1> 
<TABLE>
<TR><TD>Open</TD><TD>Close</TD><TD>Volume</TD></TR>
<TR><TD><%=NObj.Open%></TD>
<TD><%=NObj.Close%></TD>
<TD><%=NObj.Volume%></TD></TR>
</TABLE>
<H2>Time of report: <%=time()%><%=date()%></H2>
</HTML>

No Manual Compiling

To prevent the need for manual recompilation whenever a change is made, just-in-time compiling automatically recompiles the .asp files upon the next request and loads them into the server cache. So, when building your site, changes to .asp files can be previewed immediately in your browser by simply saving the file and refreshing the page.

Browser Independence

Active Server Pages provide a browser-neutral approach to application design. Because all of the application logic to generate dynamic content can be executed on the server, developers do not have to worry about what browser is used to view the site. Browsers "see" the results of an .asp file as a normal HTML page.

Scripting and Active Server Pages

Active Server Pages provide a server-side scripting environment to create and run dynamic, interactive, and high-performance Web server applications. Server-side scripting enables your Web server to perform the work involved in generating customized HTML pages. For example, you can build different views based upon who the user is, what browser they are using, where they've been on your site, or what they have purchased in the past.

Scripting languages are an intermediate stage between HTML and programming languages such as C, C++, and Visual Basic. HTML is generally used for formatting and hypertext linking purposes. Programming languages are generally used for giving complex instructions to computers. Scripting languages fall somewhere in between, much like macro languages in many desktop applications.

Active Server Pages support any ActiveX scripting language through the use of scripting engines. Scripting engines are the Component Object Model (COM) objects that process scripts. IIS 3.0 includes native support for VBScript and JScript, and plug-ins are available for REXX, Perl, Tcl, and other scripting languages.

Active Server Pages make it possible for the Web developer to use a variety of scripting languages. This is because scripts can be processed on the server side, as opposed to the client side. In fact, several scripting languages can be used within a single .asp file. This can be done by identifying the script language in a simple tag at the beginning of the script sequence.

For example, the following script example indicates that the upcoming script sequences are to be processed by Active Server Pages as JScript code and VBScript code, respectively:

<HTML>
<SCRIPT LANGUAGE=JScript RUNAT=Server>
<JScript code here>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
<VBScript code here>
</HTML>

ActiveX Components

A compelling advantage of IIS 3.0 is that it will enable component-based development of Web solutions with support for ActiveX components. Active Server Pages allow you to run ActiveX components developed in any language, such as C++, Visual Basic, Java, or COBOL. While IIS will continue to support CGI and Internet Server application programming interface (ISAPI) programs for Web-specific applications and filters, ActiveX components offer a powerful, component-based approach for applications development.

Benefits of ActiveX Components

ActiveX components, formerly known as OLE Automation servers, are designed to run on your Web server as part of a Web application. These components allow you to extend the functionality of your script behind the scenes—no interface is involved in running them.

ActiveX components are built on a popular standard. This ensures that most programmers are already familiar with developing components and that existing development tools can be used to create these components. Moreover, there are large numbers of ActiveX components already available and ready to be used as building blocks for Web-based applications.

Depending upon how they are written, ActiveX components can also be run on a Web browser and used in other environments outside the Web server, such as traditional client-server applications or application plug-ins.

Intrinsic Objects

Active Server Pages includes a number of built-in server and application building objects. These objects free developers from the grunt work of writing code to access details about incoming requests from clients, managing the application state, handling cookies, and assembling the response. These intrinsic objects include the following:

Base Components

To help you create Web applications, Internet Information Server 3.0 also provides several base components.

ActiveX Data Objects component

ActiveX Data Objects (ADO) provides high-performance connectivity to any Open Database Connectivity–compliant (ODBC-compliant ) database or Microsoft OLE DB data source. ADO allows Web developers to easily link a database to an active Web page to access and manipulate data. This enables putting a Web "front-end" on a legacy system or developing a new database-driven application for the Web. Unlike the Internet Database Connector (IDC), the ADO component can be "driven" using any ActiveX scripting language from a single .asp file.

An .asp file using ADO can dynamically request the information from a database. For example, changes in an inventory or pricing database can be immediately reflected for every user—without touching HTML code.

Content Linking component

The Content Linking component manages a list of URLs so that you can treat the pages in your Web site like the pages in a book. You can use the functionality of the Content Linking component to automatically generate and update tables of contents and navigational links to previous and following Web pages. This is ideal for applications such as online newspapers and forum message listings.

The Content Linking component references a Content Linking list file that contains the list of the linked Web pages. This list is stored on the Web server. A stream of pages can be managed and rearranged dynamically without worrying about broken links. Adding, deleting, or moving pages requires changing the order of the pages in the list file. It is unnecessary to edit the HTML on the individual pages to provide navigation.

File System component

This component provides access to reading in text files stored on the server. By providing file-system access, developers do not need to write their own code to open and close files on the file system, as most scripting languages are not allowed direct file access.

Browser Capabilities component

Using the Browser Capabilities component, .asp files can recognize the capabilities of a requesting browser and dynamically optimize the layout and content. This ensures that the Webmaster does not have to create a series of duplicate pages for each browser. For example, the http://www.microsoft.com/ site has one view for ActiveX enabled browsers, a second for frames-enabled browsers, and a third for browsers that don't support frames. Because .asp files handle the customization, there is only one copy of the content.

In the following example, the Browser Capabilities component is used to determine how to deliver dynamic advertising. If the client's browser supports ActiveX, a client-side control is sent. Otherwise, the advertising component is run on the server, which sends only a graphic image to the client.

<% 
  Set OBJbrowser = Server.CreateObject("MSWC.BrowserType")
  If OBJbrowser.ActiveXControls = TRUE Then
%>
  <OBJECT
CODEBASE="/AdvWorks/Controls/nboard.cab#version=5,0,0,5"
WIDTH=460
HEIGHT=60
DATA="/AdvWorks/Controls/billboard.ods"
CLASSID="clsid:6059B947-EC52-11CF-B509-00A024488F73">
  </OBJECT>
<% 
  Else
    Set Ad = Server.CreateObject("MSWC.Adrotator")
    Response.Write(Ad.GetAdvertisement("/AdvWorks/adrot.txt"))
  End If
%>

A Web user is not able to view the actual source code for .asp files. All the browser sees is the HTML output of the .asp file.

Advertisement Rotator component

The Advertisement Rotator component simplifies the process of displaying different advertisements or announcements by managing air-time rotation for the different images. It allows a list of different advertisements to be assigned relative display-priority percentages. Every time the .asp files are requested, the component can be used to display an ad based on the preset criteria.

Third-Party Opportunities

The components outlined above are just the beginning. ActiveX components provide excellent opportunities for third parties as organizations move to deploy Web-based solutions across intranets and the Internet. There is a limitless number of components needing to be created. Many of these will be of interest to all Web developers, while others will be designed to create custom business applications. There are currently more that 30 independent software developers writing new ActiveX components for IIS 3.0, with many more on the way.

Web developers can also create components themselves using, for example, the new Microsoft Visual Basic Control Creation Edition or Microsoft Visual J++™ development software.

Active Server Page Applications

IIS 3.0 not only provides a platform to create dynamic, personalized Web sites today, but also provides an infrastructure for powerful Web solutions in the future. This is made possible because IIS 3.0 combines the Microsoft Win32® API, open Internet standards, and the open ActiveX standard. Together they provide the best platform for Web application development.

Building Web-Based Applications

IIS 3.0 brings together the key technologies needed to run business applications on either the Internet or on corporate intranets. For example, while there are many catalogs online, very few support online transactions due to the difficulty of linking to inventory and order processing systems. By allowing organizations to move toward a component-based approach to application development, Active Server Pages help to ensure that powerful solutions can be built both quickly and easily.

IIS 3.0 truly enables component-based Web development through the support of the ActiveX components described above. IS professionals can purchase components from independent software vendors (ISVs), or reuse existing components to build powerful intranet solutions. Active Server Pages use these components to access information and publish it to the Web through scripting and HTML markup. This approach to application development offers numerous advantages, including:

Flexibility and Security

Because Active Server Pages use the same scripting and component model as Microsoft Internet Explorer, developers can choose to run scripts and components on the server and/or the client. This allows for the most efficient use of network bandwidth and server capacity for a given application. For example, a script on the client can check for missing data on a form before passing the form on to the server for processing.

Running components on the server, also places the business logic closer to the data, which has advantages in terms of efficiency and security. Web browsers make it very easy to take components and view client-side script code. With .asp files, stealing scripts or components is not possible. The source code lives only on the server and is executed to generate basic HTML.

DCOM

The components that make up an ASP-based application are usually run in the same process as IIS 3.0 for the greatest efficiency. They communicate with each other and with the server using the Component Object Model (COM).

As developers build richer applications, they will want to run components across several servers and on clients. This is enabled by Distributed COM (DCOM). DCOM takes care of all the remote procedure call (RPC) magic to make it work, so developers can use the same code no matter where the object is running. Components can talk to each other in a consistent way, using the same interfaces.

Microsoft Transaction Server

As organizations move toward deploying component-based solutions on the Web, it is critical to provide a path to scale-up these applications easily and cost-effectively with full transaction support. Microsoft will soon release Microsoft Transaction Server, code-named "Viper," a product that integrates component-based applications with transaction support.

The Transaction Server provides applications with transaction support automatically so that companies can rapidly build and easily modify server applications without sacrificing mission-critical reliability and scalability. Transaction Server is designed to work with Internet and industry standards—including HTTP, DCOM, and databases that support the X/Open XA transactional protocol—so that businesses can preserve investments in existing mainframe and UNIX systems while deploying modern applications using component software.

Microsoft Transaction Server combines the best features of transaction processing monitors, reliability and scalability, with the best features from object request brokers, distributed services and components. Transaction Server provides the vital application infrastructure that developers need but do not want to develop themselves. ISVs that develop server solutions estimate that building this plumbing into their products consumes 30-40 percent of their development costs. Active Server Page applications will be able to plug into the Transaction Server. Examples of Transaction Server services include:

Management and Configuration

As organizations begin to evaluate tools and products that enable component-based Web development, it is important to find a vendor that offers full transaction support. The combination of Internet Information Server 3.0, with Active Server Pages, and the Microsoft Transaction Server is designed to deliver on the need for Web-based solutions that can scale to Enterprise-level applications.

Summary

Microsoft Internet Information Server 3.0, with Active Server Pages, provides the ideal platform for creating and managing dynamic server-side applications that can be deployed over the Internet and corporate intranets.

Internet Information Server 3.0 allows Web site developers to manage content, design, and application logic as separate components so that team members can focus on their specialty. It also allows almost any scripting and programming language to be used and any browser to be supported. It does all of this within a no-compile development environment that frees project teams from the expense and delays of having to recompile every time an element is changed.

For organizations that are interested in reusing existing investments, purchasing turnkey solutions, or building new applications from the ground up, IIS 3.0 is the ideal environment. It simplifies the development of Web-based solutions, takes advantage of investments in languages, OLE, and existing applications, while providing a robust framework for the future.

For More Information

For the latest information on Windows NT Server, check out the Microsoft BackOffice® Web site (http://backoffice.microsoft.com/), or the Microsoft Windows NT Server Forum on the Microsoft Network (GO WORD: MSNTS).