ASP Include Files
Server-side includes let you insert the full contents of one file into another ASP page at request time, using the #include directive, so shared pieces of markup or code can live in a single file instead of being copied onto every page.
Why Use Include Files?
Most sites repeat the same header, navigation menu, and footer on every page. Without includes, that markup would have to be pasted into every single .asp file, and updating the navigation would mean editing every page one by one. An include file lets you write that shared markup once and pull it into every page that needs it.
The #include Directive
A server-side include is written as a special HTML-style comment containing #include, followed by either the file or virtual keyword and a path. It is processed by the web server before any of the page's ASP script runs, and the included content is dropped in at exactly that spot. The file keyword uses a path relative to the folder the current page sits in.
Including a File in the Same Folder
<!--#include file="header.asp"-->
<html>
<body>
<p>This is the main content of the page.</p>
<!--#include file="footer.asp"-->
</body>
</html>Using virtual Instead of file
The virtual keyword uses a path that starts from the web application's root, regardless of which folder the current page lives in. This makes virtual the safer choice for shared files, since the same include line works correctly whether the calling page sits in the site root or three folders deep.
Including a File by Virtual Path
<!--#include virtual="/includes/header.asp"-->
<!--#include virtual="/includes/footer.asp"-->- Reusable page pieces, like a shared header, footer, or sidebar navigation menu.
- Common constants or configuration values, such as a database connection string.
- Shared VBScript functions used by many different pages.
- A standard set of error-handling helpers used across the whole site.
Exercise: ASP Include Files
What is the main purpose of using an include file in classic ASP?