This article describes how to get started with Active Server Pages (ASP). This article is one of a series of articles that discuss an important "Getting Started" topic.
This article is intended for novice and intermediate customers who are familiar with computer programming. Although prior experience with a Web development language such as HTML is helpful, you do not have to have prior experience to complete the provided steps.
What is ASP?
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.
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 frquently 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.
Step 1: Install ASPWindows 2000
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. To install this option, follow these steps:
Windows NT 4.0 Server
- In Control Panel, click Add/Remove Programs.
- Click Add/Remove Windows Components, and then select the Internet Information Services check box.
- In the Windows Component Wizard, click Next, and follow the on-screen instructions.
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. To install ASP, select Internet Information Server
from the setup dialog box in which you to select components to install. Also, install the latest Windows NT 4.0 Service Pack with the Option Pack.
To install the Windows NT 4.0 Option Pack and the latest Windows NT 4.0 Service Pack, visit the following Microsoft Web sites: Windows 95, Windows 98, and Windows NT 4.0 Workstation
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. When the download wizard runs, select the appropriate operating system (for example, select Windows 95
To download the Windows NT Option Pack, visit the following Microsoft Web site: Windows Millennium Edition (Me)
ASP is not supported on Windows Millennium Edition.
Step 2: Configure a Web Application on the Web Server
After you install IIS or PWS, you must configure a Web application on the Web server. This article assumes that you are running IIS version 5.0 on Windows 2000. These instructions also work with IIS version 4.0 on Windows NT 4.0 Server, and the ASP code works on both IIS and PWS. For instructions on configuring a Web application for PWS, see the documentation that is included with PWS.NOTE
: Microsoft Visual InterDev version 6.0 and Microsoft FrontPage 2000 can automatically perform application setup for you on the Web server. If you are using one of these programs to create Web sites, you can skip the following manual setup instructions and continue directly to step 3.
- On a Windows 2000-based computer, open the Internet Services Manager (ISM). To do this, on the Start menu, click Run, type inetmgr, and then click OK. The Internet Information Services (ISM) console opens.
- Expand the top-level node that contains your computer name. Right-click Default Web Site, click New, and then click Server Extensions Web.
- The New Subweb Wizard begins. Click Next to continue. In the Directory Name text box, type the name of the Windows folder to be created for your Web application. In the Title box, type an alias that points to the underlying physical Windows folder. The title is what users see as part of the URL path when they are browsing this Web application (for example, http://www.microsoft.com/MyWebTitle). The title can be different from the underlying physical Windows folder name, but for this example, just type MyWeb for both the folder name and the title. Click Next, accept the default for Access Control, click Next again, and then click Finish.
- In the left pane of the ISM, select Default Web Site again, and press the F5 key to refresh the list of virtual folders. Note that your newly created application's virtual folder appears under the default site.
- Right-click the folder for your application, then click Properties. On the Directory tab, follow these steps:
- Select Read access.
- Make sure that Execute Permissions is set to Scripts only.
- If the Create button is available, click it.
- Close the Properties dialog box. In the ISM, notice that the icon for your virtual folder does not appear as a yellow folder but as a green symbol in a gray box. This means that your application is set up and ready to host ASP pages, so you can close the ISM.
Step 3: Create Your First ASP PageNOTE
: 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.
- Click Start, point to Programs, point to Accessories, and then click Notepad.
- In Notepad, paste the following code for the basic page structure:
<%@ Language="Vbscript" %><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>My First ASP Page</title></head><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.
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:
- 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" > [Your ASP code goes here] </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'.
<%@ Language="Vbscript" %><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>My First ASP Page</title></head><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>
Step 4: Save the ASP Page to the Web Application
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:
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:
To save the ASP page that you created in the previous step and put it in your Web application, follow these steps:
- In Notepad, on the File menu, click Save.
- 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).
- In the Save as type drop-down list box, select All Files.
- 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).
- Click Save.
Step 5: 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:
Or, if your server is serving pages on the Internet, the URL resembles the following:
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:
Additional Assistance with ASP
For more information, visit the ASP Newsgroup for peer-to-peer questions and answers. It is located under "Internet Server Programming", which located under "Web Development" at the following Microsoft Developer Network (MSDN) Online Newsgroups Web site:
For more information, visit the following Microsoft Web site:
For help with technical questions, visit the following Microsoft Web site to search the Microsoft Knowledge Base:
To get help directly from Microsoft, visit the following Microsoft Web site and open a technical support incident:
For ASP tutorials, code samples, and references, visit the following Microsoft Web sites:
For third-party ASP references and tutorials, visit the following Web sites:
Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.