Sideway
output.to from Sideway


Server Side Include file & Server Side Script Block


Draft for Information Only

Content

ASP Miscellaneous Features
  Server Side Include File
   Syntax:
   Attributes:
   Parameters:Parameters:
   Remarks:
  Server-Side Script Block
   Syntax:
   Attributes:
   Parameters:
   Remarks:

ASP Miscellaneous Features

Besides the build-in ASP objects, ASP technology also provides extra features for easier of web application design in ASP environment. The most common feature is the reusing of existing codes.

Server Side Include File

Server Side Include is one of the useful feature of ASP technology to increase the flexibility and reusing of existing contents. ASP provide a server-side include directive, #include, for inserting the content of one file into the file before processed by the web server. This feature allows some common functions, e.g. headers, footer, or elements, saved as seperated files to be reused by multiple pages.

Syntax:

<!--#include file|virtual=file name -->

Attributes:

file: The "file" keyword implies the usage of a relative path began with the file directory that contains the including file named with the "file name" parameter.

virtual: The "virtual" keyword implies the usage of a virtual path began with the virtual directory that contains the including file named with the "file name" parameter.

Parameters:Parameters:

file name

The parameter "lfile name" is the partial location of the full path that contains the including file which is either relative to folder directory or refered to the virtual folder and is enclosed by quotation marks (" ").

Remarks:

Because the #include directive is used to insert a file into the ASP file before the ASP engine processing it, the #include directive is placed outside the ASP delimiters for easier to manage. Instead of using a new HTML tag, the #include directive is placed inside a HTML comment tag for preventing the #include directive being rendered and interpreted as literal text in the HTML document by mistake. Usually the #include directive is placed immediately after the open comment character with a preceded space although the key word "#include" can be placed anywhere within the comment tag.

Since text is inserted to the ASP page before the any ASP code of an ASP page is being interpreted by ASP engine, an #include file can any form of codes, e.g. HTML tag blocks,  ASP code blocks or Script blocks. And the inserted file is immediately processed after inserted, therefore even the #include directive can also be used in the #include file. However, since the #include directive is executed before any interpretion of the ASP code script can be taken place, no ASP code can be used as the value of the parameter "file name"

<!-- #include directive DOES NOT WORK as expected -->
<% filename=(Day(date) & ".inc") %>
<!-- #include file="<%=filename %>" -->

The included file can be included more than one time in the same including file. Or the included file can include other files also. The only limitation on including file is that the included files do not form a closing loop which will cause a nesting error.

Although the included file is processed immediately after inserted, the included file is considered as a nested individual script block. In other words, HTML tags, <SCRIPT> blocks, or ASP script blocks in an included file must be a complete unit.

As contents of these included file blocks will hold up extra resources once the file is included in the ASP page, an inefficient use or waste of the limited resource may affect the overall performance and limit the scalability of web application ultimately. Therefore include file should be compact and precise. An include file with multiple functions can be broken down into smaller files with specific functions for preventing superfluous information is being included.

There is no special requirement on the file name extension. The file name extension of an included file can be .inc for easier to distinguish them from other types of files. But the file name extension of an included file can also be .asp so that these file will be interpreted before response to the client. If sensitive data is stored in the include file with file name extension used is .inc, then the IIS script mapping for the .inc extension can changed from ssinc.dll to asp.dll for taking the advantage fo the ASP engine to process the imported script. Besides , the Server.Transfer Method and Server.Execute Method are the alterenates for including file in ASP applications.

In general, both the "file" and "virtual" can be used to retrieve the same file, but there is limitation. For example, a web site is located in C:\Inetpub\Wwwroot and the application file, named apps.asp  is located in C:\Inetpub\Wwwroot\apps i.e.  C:\Inetpub\Wwwroot\apps\apps.asp.

When the "file" keyword is used with the #include directive, the parameter "file name" cannot start with forward slash or back slash. Using the "file" keyword with the name of included file enclosed by quotation marks if the included file is located in the same directory, i.e.  C:\Inetpub\Wwwroot\apps\include.inc.

<!-- #include file="include.inc" -->

Using the "file" keyword with the corresponding lower-level directory and the name of included file enclosed by quotation marks if the included is located in the a lower-level directory, i.e.  C:\Inetpub\Wwwroot\apps\inc\include.inc.

<!-- #include file="inc\include.inc" -->

If the included file is located in another branch of directory tree, a double dot, ".." with syntax "..\" can be used to raise the path to the parent or one higher-level directory. However, by IIS 6.0, the parent paths are disabled to increase security by default and an "Enable Parent Paths" option should be checked to enable the parent paths property. Besides, the single dot, "." with syntax ".\" is to return the parent directory of the including file and is same as using  the name of included file as the value of the "file name" parameter.

Using the "file" keyword with the double dot syntax for raising the path of application to the common parent directory  plus the corresponding branch of directory tree and the name of included file enclosed by quotation marks if the included file is located in the another branch of directory tree, i.e.  C:\Inetpub\Wwwroot\inc\include.inc.

<!-- #include file="..\inc\include.inc" -->

When the "virtual" keyword is used with the #include directive, the parameter "file name" can be started with forward slash or back slash. Using the "virtual" keyword with the corresponding lower-level directory refered to the root of web site and the name of included file enclosed by quotation marks if the included file is located in the same directory, i.e.  C:\Inetpub\Wwwroot\apps\include.inc.

<!-- #include virtual="/apps/include.inc" -->

And, using the "virtual" keyword with the corresponding lower-level directory refered to the root of web site and the name of included file enclosed by quotation marks if the included is located in the a lower-level directory, i.e.  C:\Inetpub\Wwwroot\apps\inc\include.inc.

<!-- #include virtual="apps/inc/include.inc" -->

Similarly, using the "virtual" keyword with the corresponding lower-level directory refered to the root of web site and the name of included file enclosed by quotation marks if the included is located in the a lower-level directory, i.e.  C:\Inetpub\Wwwroot\nc\include.inc.

<!-- #include virtual="/inc/include.inc" -->

Although include files can be placed in any directory, A better practice is to store all include files within the same application or web site. And if the include files are saved in as separated directory within the application, e.g. /inc, it is much easier to appropriate permissions to a directory for better security, since the web server read permissions are applied to all files and disable the read permissions for the include directory can prevent users from viewing the contents of include file.

An ASP page with included file is not a page with static scripting for the whole application or session scope because the ASP engine will detect any changes to the included file when this included file, included by an ASP file is being requested, before inserting the file contents to the ASP page.

Server-Side Script Block

Another useful feature of ASP technology is the server-side script <SCRIPT runat="server> element. This feature allows resembling multilines of inline script of a specific purpose into a modular base functional module as an embedded server-side function. Therefore <SCRIPT> can blocks can be reused in web design easily. To enhance the capability of server-side <SCRIPT> tag,  a new "SRC" attribute is supported as an alternative method for including another file by IIS 5.0.

Syntax:

<SCRIPT LANGUAGE=language name RUNAT="SERVER" SRC=file name ></SCRIPT>

<SCRIPT LANGUAGE=language name RUNAT="SERVER">...</SCRIPT>

Attributes:

LANGUAGE: The scripting language of the server-side script.

RUNAT="SERVER": The attribute with specified parameter "SERVER" enclosed by quotation marks (" ") is used to specify the type of script is of the server-side script runing at the server only.

SRC: The source location of the script file

...: Script statements

Parameters:

language name

The parameter "language name" is the name of the scripting language used in the script file that to be retrieved and is enclosed by quotation marks (" ").

file name

The parameter "file name" is the name of the script file that to be retrieved and is enclosed by quotation marks (" "). The parameter "file name" can be either relative or virtual paths. For example,

Relative: SRC="filename.ext"

Relative: SRC="folder\filename.ext"

 Virtual: SRC="\folder\filename.ext"

Virtual: SRC="/folder/filename.ext"

Remarks:

This feature allows the resembling of multilines of inline script of a specific purpose into a modular base functional module. For example, a <SCRIPT> block

<script language = "vbscript" runat = "server">
function strCutName(strName)
strCutName = Right(strName, 3)
end function
</script>

There is a very high flexibility in using the scripting language for <SCRIPT runat="server> element by specifying the language attribute of scripting language provided that the scripting language is supported by the ASP engine. And <SCRIPT> elements of multiple scripting languages are allowed in the same file or same web page. This feature also enable higher language flexibility in ASP page design when using <SCRIPT> blocks and becomes one of the obvious advantage of ASP technology.

<script language = "vbscript" runat = "server">
function vbCutName(strName)
strCutName = Right(strName, 3)
end function
</script>
<script language = "jscript" runat = "server">
function jCutName(strName) { return strName.slice(2)}
</script>

However, only one specified scripting language is allowed for each <SCRIPT> block.

The new "SRC" attribute only extends the capability of importing the <SCRIPT> block from a script file instead of the using of inline scripting. The <SCRIPT> block will be injected between the <SCRIPT> tags just before processing.

Unlike the client side <SCRIPT> block, the server side include, #include directive, in a server side <SCRIPT> block is not supportted since a server side <SCRIPT> is processed after  #include directive while a client side <SCRIPT> block is treated as a static HTML tage only. And therefore the server side include, #include directive is also not support in a server side <SCRIPT>.

Besides, since a scripting language is assigned to the server-side <SCRIPT> block, only the script codes of the specified scripting language in the server-side <SCRIPT> block are supported. No HTML tags or ASP code block with delimiters <%...%> are allowed since all script codes are assumed to be script statements to be processed by the specified language engine only.

And same as the #include directive, no script command can be used for the value of the "SRC" parameter also.

Although both the response.write command and other supported script statement can be placed in the <SCRIPT> element, these processing statements are usually not  to be existed as some inline processing statement by mixing <SCRIPT> blocks with ASP code blocks (<% ... %>) in the same page, becasue the result of the page respone might be unexpected as the order of statement blocks processing is controlled by the mechanism of the processing procedure of the ASP engine, not the sequence of the statement blocks.  Because of the unexpected sequence of processing the server side <SCRIPT> element due to the complexity of the script arranged by the ASP engine, the server side <SCRIPT> element is usually used for containing procedures and functions only and the sequence of the result of the server side <SCRIPT> element is injected to the page accordig to the sequence of the ASP code blocks (<% ... %>). Therefore, only in some case, the <SCRIPT> element can be used as a server side include directive.


©sideway
close

References

  1. Active Server Pages, http://msdn.microsoft.com/en-us/library/aa286483.aspx, updated 20Dec2012
  2. ASP Overview, http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx, updated 21Dec2012
  3. ASP Best Practices, http://technet.microsoft.com/en-us/library/cc939157.aspx, updated 15Apr2013
  4. ASP Built-in Objects, http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx, updated 20Dec2012
  5. Response Object, http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx, updated 20Dec2012
  6. Request Object, http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx, updated 20Dec2012
  7. Server Object (IIS), http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx, updated 20Dec2012
  8. Application Object (IIS), http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx, updated 20Dec2012
  9. Session Object (IIS), http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx, updated 20Dec2012
  10. ASPError Object, http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx, updated 20Dec2012
  11. ObjectContext Object (IIS), http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx, updated 20Dec2012
  12. Debugging Global.asa Files, http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx, updated 15Apr2013
  13. How to: Debug Global.asa files, http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx, updated 15Apr2013
  14. Calling COM Components from ASP Pages, http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx, updated 15Apr2013
  15. IIS ASP Scripting Reference, http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx, updated 15Apr2013
  16. ASP Keywords, http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx, updated 15Apr2013
  17. Creating Simple ASP Pages, http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx, updated 15Apr2013
  18. Including Files in ASP Applications, http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx, updated 15Apr2013
  19. ASP Overview, http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx, updated 15Apr2013
  20. FileSystemObject Object, http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx, updated 14Mayr2013
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx, ADO Object Model, updated 15Apr2013
  22. ADO Fundamentals, http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx, updated 14Mayr2013
close

ID: 121200006 Last Updated: 2012/12/26 Revision: 0 Ref:

IMAGE

Home (1)

Business

Management

HBR (3)

Information

Recreation

Hobbies (7)

Culture

Chinese (1097)

English (334)

Reference (65)new

Computer

Hardware (148)

Software

Application (187)

Digitization (24)

Numeric (19)

Programming

Web (540)new

CSS (SC)

HTML

Knowledge Base

Common Color (SC)

Html Entity (Unicode) (SC)

Html 401 Special (SC)

OS (367)

MS Windows

Windows10 (SC)

DeskTop (5)

Knowledge

Mathematics

Formulas (8)

Number Theory (206)new

Algebra (17)

Trigonometry (18)

Geometry (18)

Calculus (67)

Complex Analysis (5)new

Engineering

Tables (8)

Mechanical

Mechanics (1)

Rigid Bodies

Statics & Dynamics (129)

Fluid (5)

Fluid Kinematics (5)

Control

Process Control (1)

Acoustics (19)

FiniteElement (2)

Biology (1)

Geography (1)

Latest Updated Links

Copyright © 2000-2019 Sideway . All rights reserved Disclaimers last modified on 10 Feb 2019