Share via


ASP Tutorial

You can use Microsoft Active Server Pages (ASP) to create dynamic and interactive Web pages. An ASP page is a Hypertext Markup Language (HTML) page that contains script commands that are processed by the Web server before being sent to the client's browser. This explains how the term "server-side script" originated.

HTML is the simplest language for writing Web pages, but it allows you to create only static Web pages. When a Web client requests a static HTML file from a Web server, the Web server sends the HTML file directly to the client without any computation being done (Figure 1). The client's browser then processes the HTML code in the file and displays the content.

Graphic illustrating the transmission of a static HTML page.

Figure 1

VBScript is the simplest language for writing ASP pages. All the code samples in this tutorial are written in VBScript except for samples that are duplicated in JScript for comparison. When a Web client requests an ASP file from a Web server, the Web server sends the ASP file through its ASP engine, where all the server-side script code is executed or converted into HTML code (Figure 2). The converted code is then sent to the Web client.

Graphic illustrating the transmission of an ASP page.

Figure 2

Unlike conventional Common Gateway Interface (CGI) applications, which are difficult to create, ASP is designed to greatly simplify the process of developing Web applications. With a few lines of script, you can add database connectivity or advanced customization features to your Web pages. In the past, you had to know PERL or C to add such functionality, but with ASP you can use ordinary Web scripting languages such as Microsoft JScript (the Microsoft implementation of the ECMA 262 language specification), Microsoft Visual Basic Scripting Edition (VBScript), or any COM-compliant scripting language, including JavaScript, PERL, and others.

You can dramatically extend the power of ASP by using Component Object Model (COM) components in your ASP pages. COM components are pieces of compiled code that can be called from ASP pages. COM components are secure, compact, and reusable objects that are compiled as DLLs. They can be written in Visual C++, Visual Basic, or other languages that support COM.

The tutorial includes the following modules:

  • Module One: Creating ASP Pages: In this module, you write and run your first ASP pages, create data-gathering forms, connect to a database, and display a Microsoft Excel spreadsheet. You should have some familiarity with creating HTML pages before you begin.
  • Module Two: Using COM Components in ASP Pages: In this module, you use some of the COM components that are included with Active Server Pages to rotate Web advertisement banners and to record traffic at your Web site.
  • Module Three: Maintaining Session State: In this module, you learn different methods you can use to maintain session state in ASP.

Before You Get Started...

This three-module tutorial provides step-by-step procedures and samples to help you implement ASP using VBScript. To load and run the tutorial samples, you must have administrator privileges on the computer running IIS. The default IIS security settings should allow you to run the tutorial, but you may need to change your security settings if you encounter access violations.

If you get an error when you open an ASP page in the browser, try the following:

  • Close the ASP file in the text editor. The server may not be able to display an HTML page that is open in a text editor.
  • Make sure the file with the correct name and extension exists in x:\InetPub\Wwwroot\Tutorial.
  • Look at the spelling of the URL in the address bar of your browser, and correct it if necessary. It should resemble https://localhost/Tutorial/MyFile.asp or https://ComputerName/Tutorial/MyFile.asp.
  • Verify your Web server is running. A quick way to do this is to type https://localhost/localstart.asp in the address bar. If you receive a The page cannot be displayed error, your Web service may not be running. To start the Web service , click Start, click Run, and in the Open text box, type cmd. In the command window, type net start w3svc.

If your problem persists, you do not have a generic error. Carefully read the error displayed in your browser to see whether you can determine where the error is coming from. Following are examples of possible errors and their explantations:

  • Server Error: The error is coming from IIS.
  • VBScript or JScript Error: The error is probably a coding error.
  • ADODB: There may be a problem with your database.
  • Security and Access Denied: These errors are more subtle, and you need to check the permissions for your files and folders, especially for database files that require Read/Write access if you are altering data.

Web permissions are set in IIS with the IIS Manager. However, those permissions can be undermined by NTFS permissions on specific files and folders. You may allow a user access to your Web site in IIS, but if NTFS file permissions deny access to an ASP file or a database file, your Web user does not see the file. If you are using Anonymous authentication, you must set NTFS permissions to allow access to the IWAM_ComputerName and IUSR_ComputerName accounts. Please see "Access Control" in Windows Help, the "Security" section in IIS Help, which is accessible from IIS Manager, and the IIS TechNet articles about NTFS Security.

If you did not customize your installation of IIS, x:\Inetpub\Wwwroot was created as the default home directory, where x is the drive on which you installed Windows. In x:\Inetpub\Wwwroot, make a directory called Tutorial. As you work through the lessons in each module, save your work in the x:\Inetpub\Wwwroot\Tutorial directory. View your work through your Web server by typing https://localhost/Tutorial/file_name.asp in your browser, where file_name.asp is the name of your file.

By default, Internet Explorer displays generic messages when there is an error in a Web page. You will want to see detailed error messages in Internet Explorer, so you need to disable the Internet Explorer feature that bypasses the errors sent from IIS. In Internet Explorer, click the Tools menu, select Internet Options, click the Advanced tab, and clear the Show Friendly HTTP Error Messages check box.