Home > Articles > Programming > Visual Basic

This chapter is from the book

Introduction to Active Server Pages

If you are developing an intranet or Internet application, Active Server Pages is definitely worth investigating. Active Server Pages (ASP) is a component of Microsoft's Web server software that allows you to embed server-side script code in Web pages. As you know, the Hypertext Markup Language (HTML), used to created pages on the World Wide Web, is by itself static content. You can enhance this content on the client side through the use of client-side script, Java applets, Dynamic HTML, or ActiveX controls. However, Active Server Pages is a server-side enhancement because all the script code (usually VBScript) runs on the server. This means you can create Web sites that are dynamic and database-driven, yet return only standard HTML that is viewable in all browsers. A solution that uses Active Server Pages is ideal when your audience includes both Netscape and IE users, or when you want to avoid the issues associated with downloading applets or other client-side controls.


Microsoft's Web server product for the Windows NT operating system is called Internet Information Server (IIS). In addition, Microsoft Personal Web Server is available as a "lightweight" Web server for a desktop PC. The Active Server Pages component is built into both Web servers, which at the time of this writing was available for download in the NT/95 Option Pack. For a glimpse at some of the differences between these products, see the upcoming section "Virtual Directories."

Active Server Pages Versus Standard HTML

Internet Information Server identifies an Active Server Page by its .ASP extension. To create a new ASP file, you simply change the extension on an existing .HTM file or start a new text file in a text editor. The ASP file can contain either standard HTML or script code, but usually contains some of both. The script code is what makes an Active Server Page different from a standard HTML page.

Consider the URL, or Universal Resource Locator, that identifies documents on the Web. Here are two URLs, one for a standard Web page and the other for an Active Server Page:



A conventional URL (the first line) represents only a single static Web page. On the other hand, one Active Server Page (the second line) can produce many different Web pages in a user's browser, all from a single URL.

Think about how browsing works: through request-and-response communication between the browser and the Internet server. No matter what the Web server does, the end result is that a stream of HTML is returned to the browser in response to a request. When that request is for a standard .HTM file, it simply reads the file from the disk drive and passes it back to the browser. However, when the Internet server processes an .ASP file, it executes any embedded code during the process. This embedded script code can take different actions on the server, including generating the HTML that is returned to the browser.

For example, suppose that you want to create a Web page that displays the time of day when it is requested. The time of day is dynamic and cannot easily be placed in a standard static HTML page. However, you can do this easily with an Active Server Page, such as the one shown in Listing 31.1.

Listing 31.1  A Simple Active Server Page Displays the Date and Time


The Current date and time is
   Dim sTime
   sTime = Now


This ASP file in Listing 31.1 displays the current date and time. It contains a mixture of standard HTML and VBScript code. If you access the ASP file on your Web server, each time you press the browser's Refresh button, the server will execute the VBScript code, updating the date and time. However, if a user chooses to view the source in his browser, he will only see the resulting HTML:


The Current date and time is
7/5/1998 12:30:00


Notice that the server-side VBScript code is hidden from the user because it is never sent back to the browser. Because the code runs on the server, it can access databases or use custom components, as shown in Figure 31.1.

Figure 31.1

Server-side scripting allows you to create powerful Web sites.

Virtual Directories

Before you can jump right in and use Active Server Pages, you have to do a little Web server administration. As you know, the files on your Web site are located in a directory on the Web server hard drive—for example, C:\InetPub\wwwroot\financeinfo\. This path is known as the physical directory because it points to an actual location on the server's hard drive. However, when a user on the Internet wants to access files in this directory, he uses an URL such as http://myserver/finance/Monthlyreport.htm. How does Internet Information Server map the address in the URL to the appropriate physical directory? The answer is through the use of virtual directories.

In our example, the Web server knows that the virtual directory /finance is really the financeinfo subdirectory. Virtual directories act as an alias to real directories. Virtual directories, as well as many other important aspects of the Web server, are controlled with the Internet Service Manager. (Similarly, Personal Web Server is managed with Personal Web Manager.) Screenshots of Internet Service Manager and Personal Web Manager are shown in Figure 31.2.

Creating Virtual Directories for ASP Files

The process of creating a virtual directory is simple. Follow these steps:

  1. Use Windows Explorer or the MS-DOS prompt to create a new physical directory (for example, \Inetpub\wwwroot\test).

  2. Open the Internet Service Manager, which should have been installed in a program group on your server.

  3. The process of creating a virtual directory differs slightly in different versions of the Internet Service Manager: Each version of this software is pictured in Figure 31.2.


IIS can be managed remotely if you have administrative authority on the Web server.

Figure 31.2

Internet Information Server 3.0, 4.0, and Personal Web Server have different administration tools.

    Directories tab, and click the New button.

    If you have IIS 4.0, right-click your Web site and choose New Virtual directory.

    If you are using Personal Web Manager, click the Advanced icon and then the Add button.

  1. Specify the physical directory (which you can find with the Browse button) and the virtual directory (also known as the alias). For your sample, enter /test as the alias for the new directory.
  2. The next step is to set the appropriate permissions for the new directory. You should see several choices available:
  3. Read permission allows users to read files from the virtual directory. In general, you should enable this permission on all of your virtual directories.

    Script permission means that scripts can be executed from the virtual directory. You need to check this option if you intend to use ASP files in the directory.

    Execute permission is script permission plus the ability to execute other programs. (Script permission was not a separate choice in IIS 3.0).

    Write permission allows users to upload files to a directory.

    For this sample directory, you need to enable Read and Script permissions. (If you are using IIS 3.0, enable Read and Execute permissions.)

  4. Press OK to close the new directory window. You are now ready to begin placing ASP files in the directory.


Because ASP code executes on your server, think very carefully about directory permissions. If you give a virtual directory Write and Execute permission, potentially anyone on the Internet could upload his own .ASP file and execute it on your server—a very dangerous situation!

That's it! Now that you have created the /test virtual directory, you can place ASP files in it and execute them from a browser. You create your first sample ASP file and use it with the /test virtual directory later in the section "Creating a Simple ASP File."

Applications and Sessions

When designing a Web site, directory layout is important from an organizational standpoint, but with Active Server Pages, it becomes even more important because the virtual directories represent applications. In our previous example, the /test directory and the files contained within it are considered to be an ASP application. Subdirectories underneath virtual directories are also part of the application. For example, if you use Windows Explorer to create a subdirectory underneath the /test directory, then the new directory is part of the test application.

When a user first accesses any page in an application, he initiates a new session with the application. As long as the user stays within the same application and keeps loading Web pages, he is "in" the same session. However, if the user jumps to another application, closes the browser, or stops browsing for an extended period of time, then the Web server ends the session.

Why are these semantics important? As you will see, Active Server Pages contain objects and events that allow you to maintain state within a session. In other words, you can store session- and application-specific information on the server and share it between multiple ASP files.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020