Приглашаем посетить
Чуковский (chukovskiy.lit-info.ru)

16.1 An introduction to ASP and ASP.NET

Table of Contents

Previous Next

16.1 An introduction to ASP and ASP.NET

16.1.1 What are ASP and ASP.NET?

This chapter is dedicated to Microsoft Active Server Page (ASP) and its applications on the Web. ASP is a server technology developed by Microsoft in as early as 1996 to provide CGI and many other functions in the Web server. Today, two ASP products are available, namely, ASP and ASP.NET.

Since they are both server technologies, all CGI applications discussed in the last two chapters can also be accomplished by them. What is ASP anyway?

Strictly speaking, ASP is not a language but rather an environment to develop something called an ASP page to be displayed on a browser. ASP pages usually have file extension .asp and can be written by a number of languages including

  • VBScript A scaled-down version of Visual Basic.

  • JScript Microsoft's version of JavaScript or ECMAScript.

If you have installed a script engine, you can use other languages as well. We will show you how to use Perl inside an ASP page in section 16.2.2.

The ASP package is an integral part of Microsoft's systems. If you have the server software installed on Windows 95/98 such as Personal Web Server (PWS), or Internet Information Services (IIS) on NT/2000/XP, you already have ASP configured. You can also have ASP support for your Apache Web server in a UNIX/LINUX environment by installing add-on packages. These packages are available from Apache's official site (www.apache.org). ASP is universal and a powerful tool to develop Web server applications across all Windows platforms.

In late 2001, along with the .NET technologies, Microsoft released the ASP.NET package as the next generation of software for ASP for the .NET family. ASP.NET is designed for the Windows 2000 (Professional and Server versions) and XP. It is not supported on Windows NT or 95/98 platforms. If you are using the supported systems, the software can be downloaded from Microsoft's official site: www.microsoft.com or www.asp.net.

Due possibly to the huge success and wide acceptance of ASP pages in the Web community, installing the new ASP.NET software will not disturb existing ASP already in the system. In fact, both ASP and ASP.NET software can be used by the same Web server such as IIS. This means that all your ASP applications are unaffected. After installation, one of the first things you may notice is that the ASP.NET page uses a new file extension .aspx to distinguish it from .asp used for ASP pages.

Apart from some minor differences, ASP pages are practically compatible or can be migrated to ASP.NET. In many cases, ASP pages can be converted to ASP.NET without changing any coding: all you have to do is to change the file extension from .asp to .aspx.

16.1.2 My first ASP and ASP.NET page

To develop an ASP page is easy: all you have to do is to create a text file with file extension .asp. Inside this file any combination of XHTML and ASP commands can be used. ASP commands are different from text or XHTML elements, in that ASP uses the delimiters <% and %> to enclose commands that will be processed by the server. You can include within the delimiters as many commands or statements as you like, provided they are logically valid and specified by your scripting language. Let's consider a simple ASP page first.

My First ASP Page ex16-01.asp is a very simple one to display a message and a time string. Consider the following page code:



Example: ex16-01.asp - My First ASP Page
 1: <%@ Language=VBScript%>
 2: <?xml version="1.0" encoding="iso-88591"?>
 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 4:     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 5: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 6: <head><title> My First ASP Page - ex1601.asp </title><head>
 7: <body style="font-family:arial;font-size:24pt;font-weight:bold">
 8:
 9:  Now is the Time: <br /> <%=Now%>
10: </body>
11: </html>

The first line of this page specifies that the VBScript language is used. You can change to another ASP language here. If you request the page from your browser with

http://www.pwt-ex.com/book/chap16a/ex16-01.asp

you will see a message on your browser window similar to the one below (see Fig. 16.1):



Now is the Time:
22/09/2003 15:35:53

Figure 16.1. My First ASP Page

graphics/16fig01.gif


This string was generated by the statement in line 9 and the numeric part came from the ASP command <%= Now %>. This is a VBScript command to generate the date and time as a string.

The statement <%= expression %>, in fact, is called the ASP output directive and is used to display the value of an expression. This output directive is equivalent to calling the Write() method from the Response object. That is,

<%= Now %> is equivalent to <% Response.Write(Now) %>

We will cover this Response object and many others in the coming sections. From a simple server page, to CGI and databases, ASP is a powerful technology used in countless Web applications.

As we mentioned earlier, ASP pages in many cases are compatible with ASP.NET. As a simple demonstration, if you rename file ex16-01.asp as ex16-01.aspx and request the ASP.NET page using

http://www.pwt-ex.com/book/chap16a/ex16-01.aspx

you will see the same display as in Fig. 16.1 on your browser window provided you have the ASP.NET software installed. A screen shot is shown in Fig. 16.2.

Figure 16.2. My First ASP.NET Page

graphics/16fig02.gif


From a practical point of view, ASP is universal and popular across all Windows systems and many UNIX/LINUX platforms. This object-based language has an important role in Web development.

We begin by introducing the structure of ASP and its multiple scripting language features. Examples are provided to show how to use VBScript, JScript, and PerlScript with ASP. Then a series of ASP objects are discussed with applications on CGI and servers. You may find that using ASP objects to handle CGI applications is more convenient.

Along with the CGI applications, some system resources and controls are also considered in detail, namely, drives, directories, and/or files. Databases with ASP will be discussed in Chapter 17. In fact, some of the ASP objects are dedicated to database purposes. Finally, in section 16.5, the differences between ASP and ASP.NET are discussed. We will also show you how to migrate all ASP pages in this chapter to ASP.NET.

    Table of Contents

    Previous Next