Name :  Password :  
Unique page hits = 02694   
   Running
    Total
    78095

Bod's Active Server Page

Active Server Pages (ASP) was promoted by Microsoft® and is primarily used to provide dynamic interaction with you, the web surfer. Although there are other services available (e.g. JSP, PHP, Perl), ASP has gained popular appeal with web designers because of its flexibility coupled with relatively simple coding.

In most cases the ASP code is written in VBScript, a subset of Microsoft® Visual Basic. This is a very intuitive scripting language, having its roots in BASIC (Beginners All Symbolic Instruction Code - Wow! I had to brush through the cobwebs of my memory to remember that!), although it has moved on somewhat since those days.

There's no point in me going into great detail all the intricacies of coding ASP in VBScript - there are numerous sites around the internet devoted to this topic (select the ASP category in my Link Search page to find some of them). What I will do is try to share some of my experiences, and some coding work-arounds I use.

Firstly, and most obviously, the server needs to know that the page being called has some server-side ASP code to be processed. This is done by assigning the page with the '.asp' extension. Secondly, and equally importantly, the server needs to know the scripting language used in the page. This is done by putting the following as the first line of the page ...

<% @ LANGUAGE="VBSCRIPT" %>

This is especially important when developing an ASP site using Personal Web Server (PWS) 4.0, a pared-down version of IIS 4.0, running on a Windows 95 machine. If you don't include this statement then the pages may be processed increasingly slowly and ultimately the machine may 'hang up'. However you must ensure that this statement appears only once in each page else you will get an ASP compilation error.

Another important facet of ASP of which you should be aware is the 'Request.servervariables' command. This allows you to access a lot of information about about the person viewing your page. For example I know that you are using the CCBot/1.0 (+http://www.commoncrawl.org/bot.html) browser, and the IP (Internet Protocol) address of your internet connection is 38.107.179.208.

I know this because I used the commands Request.servervariables("HTTP_USER_AGENT") and Request.servervariables("REMOTE_ADDR"). You can find the Full List of available servervariables Here.

Good Coding Tips.

OK then, now for some good stuff (?) I know I shouldn't need to spell this out as I'm sure ALL coders put the term Option Explicit as the first line of their ASP code (after the @ LANGUAGE command line). No? Well you should. In this way you will help to avoid sloppy coding by ensuring that ALL contants and variables are first defined using Dim, Public or Private statements. Simply the act of thinking about your variables makes you take a more structured approach to coding.

Next, I find it most convenient to define variables and common functions in an include file which every page references. There are two methods by which the include file can be called ...

<!-- #INCLUDE file="pathname/includes/file.inc" -->

<!-- #INCLUDE virtual="/webname/includes/file.inc" -->

With the 'file' statement you need to be aware of the relative path to the include file (e.g. ../includes/file.inc). With the 'virtual' statement you only ever need to specify a single known path, regardless of the directory location of the page calling the include file. However, the 'virtual' statement depends on the server having your root directory referenced for this calling method. This is not the case for General members on the Brinkster servers so the 'file' call method is the best option.

For more coding tips please visit my Code Bank. Note: this is only accessible to folks who have registered with this site. (The Code Bank link will be active for such people). You may also be interested in my Database Test Area where you can learn about database manipulation and SQL. And on this very subject, why not check out my tutorial in my DB and SQL section. You never know - it might hold the answers to your questions.


Copyright © 2011, 2012, 2013, Ian Anderson. All rights reserved. All content in this site is provided 'as is' and no warranty is given as to the accuracy or suitability of any part hereof. No liability will be accepted for the use or misuse of any advice, real or implied, which may be contained herein. All trademarks shown belong to their respective owners.
If you like what you see and would be interested in contracting me to develop a web site for you, then register your interest via my Job Page and I will contact you to discuss your requirements and the terms of contract.


Click for details