(unresolved tag dir /topics/asp.html)
ASP (Active Server Pages)
Active Server Pages (ASP) is Microsoft's core technology for active Web server content. It's a scripting engine which runs under IIS. Here are its interesting features:
  • Windows-specific technology
    ASP was made as an active content engine for IIS and as such Microsoft built it for NT. On the other hand, for IIS it's the default (non-CGI) method of providing active content.
  • Nice code embedding syntax
    One of the returning irritants with active code is how to integrate the code and the HTML which presents the results of the code. With ASPs, both code and layout are in the same file, which I don't like, but at least the way they're in the same file is easy to work with.
  • ASP scripting "optimized for" Windows-style object orientation
    Just can't help falling into Microspeak when I think ASP. ASP, like all Microsoft's recent technologies, is ActiveX-object-oriented. If you have ActiveX objects, it's really easy to use ASPs to integrate them with Web applications.
  • Good session model
    The ASP Session object provides a really convenient cookie-based session tracking.
Now on to some other thoughts and a little intro to how to write an ASP.

Other platforms
By the way, if you decide you want Unix after all but you've already developed a pile of ASPs, no big deal. Microsoft won't help you, of course, but a bunch called ChiliSoft can, with ChiliASP. And the "Personal Web Server" (PWS) can also run ASPs and will run under Win95 or Win98. Since I run Win95 on my own development box and Win98 on my laptop, I like to have PWS there to test ASPs when I actually have to write some. So in all the following, when I say "IIS", read "IIS or PWS or some weird ChiliASP-running Unix box or something."

The typical ASP scenario, of course, is that you've got IIS on an NT box already, perhaps for political reasons, and you have to get some sort of active application on there. ASP makes it pretty easy. It provides an embedding syntax and a scripting language. VBScript is the default scripting language, and even though Javascript (or even Perl, I understand) can be used as the scripting language for an ASP, nearly everybody uses VBScript.

That scripting concept
In fact, since it's a scripting language, most IIS-only programmers refer to any Web programming as "scripting." Microsoft seems to encourage this viewpoint in their documentation. If you want my usual conspiracy-theory view, they want you to believe that scripting is used as the glue, while you "drop down" into a serious -- and more expensive -- language to do serious work.

And in fact VBScript was designed with limitations in mind, from the number of variables you may declare, to the total data size of a script. So conspiracy theory or not, you can only do so much in VBScript.

How to write your own ASP
I'm off track again. What I wanted to do with this topic is to present a kind of "how to get started" with an ASP from scratch. Document the basic mechanisms and go from there. Well, first you have to realize that the file extension tells IIS (or PWS) what to do with each file called. ASPs have a (default) extension of .asp, which makes a lot of sense. All that extension tells IIS is to run the page through the scripting engine. If you don't do any scripting, the contents of the file are spit out verbatim. So key number one:

An ASP is just HTML with some extra stuff.
OK, so how do we get the server to run some stuff, then? Well, just as you can use a <script> tag to get the browser to run some code, you can use the same tag to tell the server to run code, if you mark it with runat="server". Personally I find this rather confusing, as it's difficult to see at a glance whether the script should run on the server or on the client.

For that reason, instead of that tag syntax, I use the shorthand server-scripting syntax instead. If you enclose any text within <% ... %>, then the enclosed text is considered a server-side script. That's much cooler-looking anyway.

The simplest thing to do with a server-side tag is just to write the value of some variable or function call. And one of the simplest function calls is to read something out of the query URL: this can be done with Request("name of query"). For instance, I have a query of the form my.asp?myquery=hi+there -- if my.asp contains this code:

<b><%=Request("myquery")%></b>
then it will appear like this:
hi there
VBScript
The next logical thing to write about would be VBScript and its object model, but I'm not going to do that. VBScript is a neat little language, and it's salient to more than just web programming, so it will (eventually, of course) get its own topic. When and if I have time to write up a topic on it, I'll link it here.

Applications and global.asa
Instead, I'm going to talk very shortly about the concept of an application in the WinWeb world. An application is effectively a group of ASP files which are grouped together in a directory. But where it gets interesting is that IIS also keeps track of whether anybody has hit a page in that directory or not since the server started up (insert tirade about how much more often this is under NT than under Unix, heh). And if you use a Session object, it will also track whether a session is starting up or not.

So what? Well, if you include a file in your application directory called global.asa, then IIS will use that file to create objects (use the <object> tag with runat=server) or create any of four functions: Application_OnStart, Application_OnStop, Session_OnStart, Session_OnStop. Anything else and IIS will complain. At least, the underscored nomenclature is used if you're doing VBScript. I assume Javascript would want dots. Anyway, the _OnStart functions are useful for creating and initializing objects. (If the object can handle its own initialization then just use the <object> tag.) The Session_OnStart can initialize anything connected with the user session.

Onwards
There are some other points I want to cover here eventually, such as the whole object-oriented WinWeb philosophy, which I find rather interesting. So stay tuned and, as always, ask questions if you want to see some action.

LINKS
Links will be coming whenever I have time to look some good ones up; for Windows programming I don't usually use online resources that often. This has two main reasons: first, I have lots of offline resources instead, and second, I just have never seen much in the way of decent documentation for WinWeb work. But before I get on that soapbox, I'm going to get back to the paying work.





Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.