# Discussion

ASP is a set of software components that run on a Web server and allow Web developers to build dynamic Web pages. The advantage of ASP over static HTML Web pages is that an ASP page is like a computer program that runs on a Web server and can calculate results, process user input, read from or write to databases and files, and insert "live" updated content every time a user browses the page.

## Related Technologies

ASP runs with a Web server on the Microsoft Windows platform. The Web server that is used is Internet Information Server (IIS). It is also possible to run ASP with a limited feature set on Microsoft Personal Web Server (PWS), which runs on Microsoft Windows 95, Microsoft Windows 98, and Microsoft Windows NT Workstation. ASP can also run on Unix operating systems by using special extensions that are created by software vendors.

Because ASP is frequently used to create business applications on the Web, it is regularly used with databases such as Microsoft Access, Microsoft SQL Server, or databases from other vendors. When used in conjunction with a database, ASP pages can even run transactional applications, such as those used by banks, by using the features of COM+ or Microsoft Transaction Server (MTS). A number of tools can be used to create ASP pages, ranging from simple text editors such as Notepad, popular Web site creation tools by Microsoft and other vendors, or a full-featured programming tool such as Microsoft Visual InterDev.

## Running ASP

ASP version 3.0 is included with all versions of the Microsoft Windows 2000 operating system. ASP is installed automatically when you install the Internet Information Services option with Windows 2000. The older version of ASP, version 2.0, runs on Microsoft Windows NT 4.0 Server, which requires you to install the Windows NT 4.0 Option Pack. ASP version 2.0 also runs on Windows 95, Windows 98, and Windows NT 4.0 Workstation by installing Personal Web Server (PWS). PWS is included with the Windows NT Option Pack. However, ASP is not supported on Windows Millennium Edition.

Please Note: due to  DotNetNuke Text Editor problems with the less than and greater than characters, these have been replaced in this article with "[]" brackets.  If you copy and paste the markup in this article, you'll need to replace the "[]" brackets with the corresponding greater than and less than characters.

# Creating Your First ASP Page

For this example, do not use Visual InterDev or FrontPage to create an ASP page. Although both applications can create ASP pages easily, it is better for learning purposes to hand-code the ASP page in a simple text editor such as Notepad.

In Notepad, paste the following code for the basic page structure:

[%@ Language="Vbscript" %]
[html]
[meta http-equiv="Content-Type" content="text/html; charset=windows-1252"]
[title]My First ASP Page[/title]
[body]
[/body]
[/html]

Type some ASP identifier tags and ASP code in the page. Note that for ASP code to run, it must be identified by one of the following sets of tags. The Web server uses these tags to identify the code that must be processed on the server before it returns the page to a browser. ASP identifier tag 1:

[% [Your ASP code goes here] %]

In this approach, you create an opening tag with the less than ([) and percent (%) symbols, a closing tag with the percent (%) and greater than (]) symbols, and you write your ASP code between the opening and closing tags. ASP identifier tag 2:

[Script runat="Server" ]
[/Script] 

In this approach, the script tags are the same as the HTML script tags, except that the opening script tag has an attribute called runat='Server'. As an example, put a pair of ASP tags between the body tags in your ASP page. Between the ASP tags, input the following VBScript code sample so that the completed version of your ASP page resembles the following:

[%@ Language="Vbscript" %]
[html]
[meta http-equiv="Content-Type" content="text/html; charset=windows-1252"]
[title]My First ASP Page[/title]
[body]
[%
'Use an apostrophe to delimit code comment lines like this one.
'Declare variables.
Dim strGreeting, strTime, strTotal
'Process and calculate.
strTotal = 10 * 21
strTime = Now()
'Create a string that inserts the value of the two earlier
'variables.
strGreeting = "Hello World! The current date and time are: " & _
strTime & _
".[BR]" & "The result of our calculation is: " & _
strTotal
'Output the results to the browser
Response.write strGreeting
%]
[/body]
[/html] 

# Save the ASP Page to the Web Server

Now save your ASP page to the Windows folder that is created for your Web application in step 1. When you used the Server Extensions Web Wizard in step 1, you typed a folder name for the physical Windows folder that contains your Web application's content, and then the wizard created the folder for you. By default, the wizard creates the new folder and subweb in the root site for IIS. Because you used the name MyWeb for your folder and your title alias, the typical path to it on your system resembles the following:

C:/Inetpub/Wwwroot/MyWeb

When the MyWeb application is running under IIS, and you use a Web browser to view the application, the URL path for the application starts with the Web protocol (http://). Next, if this is a local Web that is only on your computer or on your company intranet, use your Windows computer name (for example, MyServer), or for publicly accessible Internet sites, use your domain name (for example, www.MyCompany.com). Finally, append the alias or title of your Web application's subfolder. The resulting URL resembles the following URL:

http://MyServer/MyWeb

-or-

http://www.MyCompany.com/MyWeb

To save the ASP page that you created in the previous step and put it in your Web application, follow these steps:

2. In the Save As dialog box, use the Save In drop-down list box to locate your application's physical folder (for example, C:/Inetpub/Wwwroot/MyWeb).
3. In the Save as type drop-down list box, select All Files.
4. In the File Name text box, delete any default file extensions that you see, and then type your file name with the ASP extension (for example, Default.asp).
5. Click Save.

# Use the Web Server to View the Page

Open a Web browser, such as Microsoft Internet Explorer. In the address line, type the URL to your new ASP page. For example, if your server is running locally (that is, it is not serving pages on the Internet), the URL resembles the following:

http://MyComputerName/MyWeb/Default.asp


Or, if your server is serving pages on the Internet, the URL resembles the following:

http://www.MyCompany.com/MyWeb/Default.asp


Note that new Web applications in IIS are automatically set to use either Default or Index as a default file in the virtual folder for your Web application. In other words, if you use Default.asp as the name for your home page or the first page in your application, you do not have to use the file name in the URL. You can just locate the virtual folder that contains the Default.asp page, as follows:

http://MyComputerName/MyWeb/
• 本文已收录于以下专栏：

举报原因： 您举报文章：Introduction to Active Server Pages 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)