Microsoft & .NETASPSo, You Want ASP, Huh?

So, You Want ASP, Huh?

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.


Use these to jump around or read it all…

[ASP, What’s That?] [Is ASP A Language?] [Can I Use ASP?]
[Test For ASP Yourself!] [How You Do It]

(The following performed with Twilight Zone voice):
     You’re surfing along and everything looks okay, but then you look up at the location bar. There’s no .html up there. It’s new. Instead there’s an .asp. Signpost up ahead. You have entered the Active Server Page Zone….

     And there’s probably a monkey tearing up the wing out the window. Now, here’s the fun part. I get to try and explain this Active Server Page process in 1000 words or less. To get a better handle on all of this, I actually hired a guy to sit and talk with me for a couple of hours and explain it all. It’s amazing how expensive brainy people are! These are the type of things I do for you people….
     The purpose of this tutorial is to get you familiar with the ASP process and hand out a couple of ASP examples for you to play with on your own pages.


ASP, What’s That?

     It’s actually a pretty interesting way of doing things. Let me attempt to get it all into a nutshell.

     If you haven’t connected the dots yet–ASP stands for Active Server Pages. The concept is pretty straightforward. Imagine that you have an office of 50 people. Each of them has their own phone line. You would like to show their phone usage (a very business-like way of saying “bill”) over the Internet. You could do it by creating 50 different pages every night at midnight when the phone bill is compiled. That would work, but would be very labor-intensive. Or you could set up an ASP system to do the work for you.
     You would create a text-based page and give it an .asp extension. That page would act as a template for the 50 different pages it will produce. Employee A logs in and offers a password to prove that he is who he says he is. The ASP page is then called upon. The template grabs the person’s name, along with a few other basic items found in an employee database set up on the same server as the page. Then a second database, the one with all the phone records, is contacted and that person’s phone usage is gathered.
     All these pieces of information are then displayed to the viewer in the form of an HTML page. You can look at the source code, but you won’t see the template. You’ll see the HTML code produced by the template. All of the work is being done by the server rather than by coders. It’s all very clever.

     ASP really shines here in that it doesn’t involve the browser to do the work. At the moment there are a lot of error messages being thrown around the Web because a person is attempting to look at a Web page designed specifically for Internet Explorer using Netscape Navigator. Silly surfer, CSS is for kids!
     But ASP does all of its magic before the browser gets the page, so what browser the user has matters very little. The server does all the work rather than relying on the browser to read all the tags and see the CGI which contacts the database, which then replies with a code that is placed in the browser window–hopefully–in a scripting language the browser understands.


Is ASP A Language?

     No. ASP is the name of the process. The computer language most commonly used to make Active Server Pages is Microsoft’s VBScript. The reason is that ASP itself comes from the utility research kitchens of Microsoft.
     My ASP wizard informs me that ASP-style events can be created using JavaScript, PERL, and C++, but true ASP is done using VBScript.


Can I Use ASP?

     I don’t know. I hope so, but you’ll have to find the answer to that question server by server. You may have heard that ASP was a “Microsoft” thing. It is. Your server, not you, your server must be running the Microsoft I.I.S. (Internet Information Server) operating system, version 3.0 or higher. If not, there’s no ASP for you. And before you write and ask me, as someone always does, No, there is no way to “trick” your server into understanding and running ASP if it is not configured to do so.
     Case in point: Notice this page is named “asp.html.” Notice it is not an Active Server Page entity. Why? Because the servers HTML Goodies sits upon run a UNIX operating system. My own servers don’t support it. Bummer.

     Mitch Vassar was nice enough to tell me that you can play with ASP on your own computer running Windows 95/98 by grabbing Microsoft’s Personal Web Server. In fact, you may already have it. It comes bundled with the Windows NT Option Pack 4.0 and the VB6.0 disc. You may also want to check if it’s available with your version of FrontPage.

     Please understand that using the Personal Web Server will allow you to play with ASP on your own computer. You cannot just upload it and get your server to run it.


Test For ASP Yourself!

     Every so often I get a letter from a Webmaster telling me to stop telling my readers to ask their Webmaster if the server is configured a certain way. It can get tedious answering the same question again and again.
     So, what I’m going to do is give you a very simple ASP “template” page that you can copy, paste, and post to your system. Then go look at it with your browser. If you see the correct results, you’re in. If not, join the crowd. Here ya go:


<%@ LANGUAGE=”VBSCRIPT” %>

<!— You should get —>
<!— current system date and time —>

<HTML>
<HEAD>
<TITLE>ASP Test Page</TITLE>
</HEAD>

<BODY>
Today’s date and time is <%=Now()%>.
</BODY>
</HTML>


     Copy everything between the horizontal lines and paste it to a text editor. Make sure you then save it to a file in a text-only format, just like you would any other HTML document.
     Save the file as “test.asp.” Do not save this with an .html suffix. If you do you’ll kill the entire test.
     Next, FTP the file to your Web server. You must look at this test file from your server rather than your hard drive if you want to get a true reading. The reason is that this file uses VBScript, which Internet Explorer understands just fine. It might give you the correct results from your hard drive. That’s not good.
     Finally, go look at the file online. You do not have to “turn it on” like certain files in UNIX. If you have the right server operating system, it’ll just work. If you get this:

Today’s date and time is

     …you do not have ASP abilities, but if there’s a date after that line, you’re in!


A Useful ASP Example: SSI

     After talking with my ASP wizard, I asked him if he could write a few useful ASP examples I could hand out to people online. He said he would… for a nominal fee. I really have to look up what the word “nominal” means when I get a chance.
     He and I put together five ASP examples that perform popular tasks (at least tasks that are popular with HTML Goodies readers). I intend to offer all five over four different tutorials. You’ve already got one: The first is that simple date and time test file up there.

     The second ASP example you’ll get here is an effect that people have been screaming for for quite some time now. It’s called an SSI or Server Side Include. This, too, is a simple one, but hey, this is just the introductory tutorial.
     Dig this: You have a series of 50 pages again. At the top of every page you want to put a greeting which you’ll update every day. You can go in and change all 50 pages, each time you change the text, by hand. But that’s a killer in terms of time.
     But imagine if your daily greeting is simply a page unto itself. Then, on each of the 50 pages, you had a line of code that would take what was on that greeting document and post it to the page. That way, when you update the greetings page, you update all 50 pages because they all have a line of SSI code. And wherever that SSI code sits is replaced with the text on the greeting page when the page is loaded.
     It sure would make updating pages quicker. I know. I use SSIs all the time on the HTML Goodies pages. I just use a different method than this one I’m about to give you. But that’s another tutorial.


How You Do It

     This is an ASP event, so you must be running this off of a server that can do it. What browser the user has is immaterial. The server is the thing in ASP.

     First, we create the page that contains the text to be inserted. I called it the “greeting” page in the example above. This text can be anything including HTML code, scripting, or anything. The server doesn’t care. It’s just going to replace the SSI command with whatever is on this page. Just remember, this page does not have to be a fully formed HTML document, or any type of document for that matter. It can just be a line of text with no alterations at all. Whatever is contained will simply be included where another page has the SSI command.
     Save the page with a name and an .asp extension. It has to have the .asp extension. For this example we’ll say we named the file “greeting.asp.”
     Next we’ll create the page that is calling for the text included in greeting.asp.
     Each page that will contain the SSI will need to be saved with the .asp extension. Always — no exceptions.
     In addition, all pages that will contain the SSI will need to have this as its first line:

<%@ LANGUAGE=”VBSCRIPT” %>

     Get that line above everything including the DTD and the <HTML>. Always. No exceptions.
     Now the simple part. Wherever you want the text of the file greeting.asp to appear, place this command:

<!– #INCLUDE FILE=”greeting.asp” –>

     When the page loads to the browser window, you’ll have the text of the file greeting.asp where that SSI command above was placed. The source code will never show that command. Just the text from the other file.
     It’s a very slick little system. Just remember that the SSI command above is set up to display a file called greeting.asp. You’ll need to change out the file name to whatever you name your own inclusion file.


That’s That

     That’s the beginning skinny on Active Server Pages. I have three more examples lying in wait for the next three new tutorial posts. They are (1) An honest to goodness working password system, (2) a random ad banner event, and a (3) guestbook event that displays a “thank you” page that you can fully create. Other suggestions will be accepted via e-mail!

     So go! Find out for yourself if you can run Active Server Pages. If so, you’re in for some fun. My server at school has ASP capabilities. It’s really slick, and a lot of fun to play with.

  Enjoy!

[ASP, What’s That?] [Is ASP A Language?] [Can I Use ASP?]
[Test For ASP Yourself!] [How You Do It]

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories