Active Server Pages (ASP):

There are 3 different codes:

1. HTML code. The HTML code is sent to the user's browser first, then, it is evaluated.

2. Active Server Pages (ASP) code. The ASP code is evaluated before it is sent to the user's browser.

3. Server-side includes (SSI) commands. The SSI commands are inserted into ASP and HTML file. Then, they are evaluated before the actual ASP code is evaluated.

 

The Key difference between Active Server Pages code and HTML code is that ASP code is always kept on the server. The ASP code is evaluated before it is sent to the user's browser.

 

Server-side includes (SSI) provide another way to build the ASP page before it is sends to the user.

The Server-side includes (SSI) commands are inserted into ASP and HTML files that are evaluated before the actual ASP code is evaluated.

 

The Server-side includes (SSI) commands can do the following into your page:

1. Insert the value of an environment variable into a page.

2. Run an application or command and insert the results into a page.

3. Insert the time a file was last modified into a page.

4. Insert the size of a file into a page.

5. Include a file into another file.

 

Modular Code:

Because these commands are run before the ASP commands are run, you can use server-side include directives to create modular code.

For instance, include a constants file into your pages so that you can use named constants instead of numbers.

This process uses the include directive available in server-side includes.

You can also have one file include other files. Create a file with your subroutines an include it anywhere you need it.

 

The Server-side includes (SSI) Directives:

If a server-side include directive doesn't work as expected, you can always write ASP code to do the same work.

Non of these directives except for #include will work within ASP files.

 

#config Directive

You can configure 3 SSI options on a page-by-page basis.

1. You can set the error message to be displayed when an SSI-related error occurs.

These errors can include file not found errors (for includes), failed commands (for execs), and so forth.

The default behavior is to display the actual error; however, if you're running a site, you may not want visitors to see the actual error text.

 

To make this change, use the following code:

<!-- #config errmsg="A server error has occurred." -->

 

2. How dates and times are displayed when they are created through SSI directives.

SSI directives can generate time and date results, and the options you set control how they are displayed.

<!-- #config timefmt="%H:%M:%S" -->

 

You can streth the #config line on the same line to work properly.

<!-- #config timefmt="The %dth day of %B in the year of our Loard%Y" -->

%d = 01-31 days, %B = January ... December, %Y = the year 1996 ... etc.

 

3. You can configure the file sizes.

<!-- #config sizefmt="BYTE" --> It return sizes in bytes.

<!-- #config sizefmt="ABBREV" -->  It return sizes in kilobytes.

 

 

#echo Directive

This SSI directive displays the value of an HTTP variable. Whenever you visit a Web page, there are information made available about you, your browser, and session information. You can retrieve these values.

 

To Display information in the Web page:

You are visiting the host named <!--#echo var="SERVER_NAME" -->

 

To do the same thing in an ASP page:

You are the host named <% = Request.ServerVariables("SERVER_NAME") %>. <P>

 

 

#exec Directive

This SSI directive enables you to execute a command on the server. The result will be displayed on the Web page containing the directive. Most Web servers have this option turned off because it is a HUGE security hole.

Example:

Results of "dir" Command:

<P>

<!--#exec cmd="dir" -->

You can specify a CGI script by using cgi instead of cmd.

 

 

#flastmod Directive

This directive returns the last date/time a file was modified. This is helpful to put at the bottom of your pages so that the user can see when the Web page was last modified.

<!--#config timefmt="%B %d, %Y" -->

Last modified: <!--#flastmod file="test.shtml" -->

 

You can also specify the virtual Web path to your file:

<!--#config timefmt="%B %d, %Y" -->

Last modified: <!--#flastmod virtual="/index.shtml" -->

 

This feature is not available in ASP pages, you need to use different code and create a function to make this work.

 

 

#fsize Directive

This SSI directive returns the size of a file.

This feature is handy if you are providing a list of links to files but don’t want to update the listing manually when the file sizes change.

File Size: <!--#fsize file=”data.zip” à

This code prints the size of the file in kilobytes.

The #config directive will change whether the file size is printed in bytes or kilobytes.

 

This SSI directive doesn’t work in ASP pages. Instead use the FileSystemObject to get this information.

 

 

#include Directive

This SSI directive is used to include one file’s contents into another. This is the only SSI directive that works in both ASP and HTML pages. Here’s an example that will include a file in the same directory:

<!--#include file=”adovbs.inc” à

 

To load a file in another directory, use the virtual parameter instead:

<!--#include virtual=”/includes/adovbs.inc” à

 

One limitation to this directive is that you cannot dynamically generate the file name you want to include because all #include directives are processed before the ASP code.

 

 

Creating Modular ASP Code

These Modular ASP code files are easier to manage. You can make changes to your function library without updating every page for minor changes.

 

The problem with using file extensions other than ASP for your include files is that they can’t be processed for further #include directives. You must use ASP as file extension for your include files.

 

If you want to use a single #include directive in your file, but you don’t want all your functions in one file.

This means that you have multiple files with functions in them, all of which need to be included into a file, which is then included into each of the other files.

Include FunctionLibrary.asp into each of your files where you want to use the functions you wrote.

In addition, if you ever add new functions or new function files, you simply make the new files and then add the appropriate #include directives to FunctionLibrary.asp.

 

Keep all your include files in a common directory, named something like includes or scripts.

Then use the virtual parameter in the #include. This enable you to use the ASP library files from anywhere on your Web site without encountering problems in finding the proper directories.

 

None of the code will ever be sent to the user’s browser. Instead, it will all be evaluated on the server, which means you can essentially create any level of file hierarchy that you want.