What Can Be Done to Improve ASP Design?
Even though ASP scripts are, obviously, scripts, there are several
approaches that can be taken to modularize your source code and
encapsulate complex tasks. These
include using server-side includes, taking advantage of VBScript
classes, and making calls to the
Server.Execute
and
Server.Transfer
methods.
Server-Side Includes
One of the most common approaches to creating modularized code is to use server-side includes (SSI). Server-side includes are used to import ASP code into an ASP page. The benefit of being able to import code from one ASP page to another is you can create individual ASP pages with common functions or classes, and have these functions and class definitions imported into the pages that require their use. Instead of having to cut and paste a particular function that is needed in several ASP web pages, you can place that function in a single file, and then use a server-side include to import the function definition into each ASP page that needs to make use of that particular function.
For example, imagine that you run an e-commerce site. Conceivably, there are a number of ASP pages
in which you need to compute the sales tax.
Rather than hardcode a sales tax percentage in each of
these pages, you could create a single
function—ComputeTotalWithSalesTax—that
would accept the total less the sales tax as a parameter, returning
the new total including sales tax.
Example 1.1 contains an example of the
ComputeTotalWithSalesTax
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access