Microsoft KB Archive/301097

= How To Build Your First ASP Web Application in Microsoft Active Server Pages =

Article ID: 301097

Article Last Modified on 4/14/2006

-

APPLIES TO


 * Microsoft Active Server Pages 4.0

-



This article was previously published under Q301097





IN THIS TASK
SUMMARY
 * Install ASP
 * Configure a Web Application on the Web Server
 * Create Your First ASP Web Page
 * Save the ASP Web Page to the Web Application
 * Use the Web Server to View the Page

REFERENCES



SUMMARY
This article describes how to get started with Active Server Pages (ASP) and 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 step-by-step procedure.

back to the top

Install ASP

 * 1) Click Start, point to Settings, and then click Control Panel. In Control Panel, click Add/Remove Programs.
 * 2) Click Add/Remove Windows Components, and then select the Internet Information Services check box.
 * 3) Click Next, and follow the on-screen instructions.

back to the top

Configure a Web Application on the Web Server
After you install Microsoft Internet Information Services (IIS) or Personal Web Server (PWS), you must configure a Web application on the Web server. This article assumes that you are running IIS version 5.0 on Microsoft Windows 2000.
 * 1) Open the Internet Services Manager (ISM). To do this, click Start, click Run, type inetmgr, and then click OK. The Internet Information Services (ISM) console opens.
 * 2) Expand the top-level node that contains your computer name. Right-click Default Web Site, click New, and then click Server Extensions Web.
 * 3) In the New Subweb Wizard, 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 text 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 view this Web application (for example, http://www.microsoft.com/ ). 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.
 * 4) In the left pane of the ISM, click Default Web Site, and then press F5 to refresh the list of virtual folders. Note that the virtual folder of your newly created application appears under the default site.
 * 5) Right-click the folder for your application, and then click Properties. On the Directory tab, follow these steps:
 * 6) * Select Read access.
 * 7) * Make sure that Execute Permissions is set to Scripts only.
 * 8) * If the Create button is available, click it.
 * 9) Close the Properties dialog box. In the ISM, note that the icon for your virtual folder no longer appears 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.

back to the top

Create Your First ASP Web Page
NOTE: For this example, do not use Microsoft Visual InterDev or Microsoft 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 your blank Notepad document, paste the following code for the basic page structure: <%@ Language=&quot;Vbscript&quot; %>  My First ASP Page

  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:  [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'.</li></ul>

As an example, put a pair of ASP tags between the 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=&quot;Vbscript&quot; %> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;> My First ASP Page

<%   '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 = &quot;Hello World! The current date and time are: &quot; & strTime & &quot;.<BR>&quot; &  _ &quot;The result of our calculation is: &quot; & strTotal

'Output the results to the browser. Response.write strGreeting %>

</li></ol>

back to the top

Save the ASP Web Page to the Web Application
Now save your ASP page to the Windows folder that was created for your Web application in step 1.
 * 1) In Notepad, on the File menu, click Save.
 * 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) For Save as type, 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.

back to the top

Use the Web Server to View the Page
Open a Web browser, such as Microsoft Internet Explorer, and type the URL to your new ASP Web page in the Address bar. For example, if your server is running locally (that is, it is not serving pages on the Internet), the URL resembles the following:

http:// /MyWeb/Default.asp

On the other hand, 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/

back to the top

<div class="references_section">