Article

Getting Started with ASP

Page: 1 2 3 4 Next

Your First Script

You should begin by making sure your Web server is operating properly by putting up a simple Web page and viewing it using your browser. If you’ll be using a Web host for your ASP development, then you are probably familiar with the steps involved. Typically you must use an FTP program to put the Web page on your Web host’s server, and then you can access it with your Web browser by typing the address (e.g. http://www.mywebsite.com/testing.html).

If you’ve installed Web server software on your own computer, a similar process is involved. Instead of sending the file to the server via FTP, however, you just have to place the file you want to make available in the directory your Web server expects. Microsoft IIS and PWS both default to using C:\Inetpub\wwwroot\. Once a file has been placed in that directory, you can view it by opening your Web browser and typing the address http://localhost/file.html, where file.html is the name of the file that you placed in the directory.

Note that placing the file in the appropriate directory and using the above address is very different from just using the "File | Open..." menu command in your browser to view the file directly off your hard drive. By typing the address, you are instructing the browser to request the file from the Web server running on your computer. This gives the server software a chance to process any ASP scripts that the Web page might contain. If you open the file directly using "File | Open...", or by typing the path and filename (i.e. C:\Inetpub\wwwroot\file.html) into the address field, the server doesn't get a crack at the file first, and server-side scripts will not be processed. That's why it's important that you always open ASP pages on your computer using the http://localhost/ address.

Now, assuming you're able to put a basic HTML Web page on your server and view it as described above, you should now be ready to try your hand at writing and viewing an ASP script. Open Notepad, or whatever text editor you prefer (programs like UltraEdit, HotDog Professional, HomeSite, and Visual Studio all provide convenient support for highlighting of ASP code, among other features), and type the following code:

<html>
<head>
<title> My First ASP Page </title>
</head>
<body>
<%
' Write out a simple HTML paragraph
Response.Write "<p>This is a test of ASP.</p>"
%>
</body>
</html>

If you're thinking this code looks remarkably like an HTML file, you’ve got the right idea. Save the file as asptest.asp. In Notepad you'll need to either select "All Files" in the "Save as type" drop-down menu or enclose the filename in double quotes ("asptest.asp") to avoid having your file renamed to asptest.asp.txt. If you're working with a Web host, upload the file to your account using FTP, or whatever alternative method your host provides. If you're working with server software running on your own computer, copy the file to the Web root folder of the server (C:\Inetpub\wwwroot for IIS or PWS).

Now, try viewing the ASP page in your Web browser by typing its address. This should be something like http://www.mywebsite.com/asptest.asp if you placed the file on a Web host, or http://localhost/asptest.asp if you're working with a server running on your own computer.

asptest.asp

What you should see is a Web page containing the words "This is a test of ASP." much like that shown above. If instead you get a blank page, chances are good that your Web server did not process the ASP code. Try the "View Source" function of your Web browser. If the code of the page appears exactly as you entered it above, then there is definitely something wrong. Remember, the ASP scripting engine in the Web server is supposed to process the ASP code and convert it to plain HTML before sending it to the Web browser. In fact, if everything works like it's supposed to, you should see the following code when you use "View Source":

<html>
<head>
<title> My First ASP Page </title>
</head>
<body>
<p>This is a test of ASP.</p>
</body>
</html>

Notice how the ASP code, which began with <% and ended with %> has been replaced with the HTML code for a simple paragraph of text. If this isn't happening, then either you're not viewing the page through your Web server (that is, you used "File | Open..." to open the page in your browser, as I warned you not to), or your Web server's ASP support is not working (or is non-existent). If after reviewing these possibilities you're still stuck with a test page that isn't working properly, post your question in the SitePoint Community Forums, or email me directly and I'll assist you as my schedule permits (generally, you'll get a much quicker response from the forum community).

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links