Chapter 38: ASP Including Files

1. What does “Including Files” mean in Classic ASP?

Including files means taking the content of one .asp / .inc file and inserting it into another file at runtime — exactly as if you had copied and pasted the code yourself.

It is the only way Classic ASP had to reuse code across multiple pages before modern concepts like classes, partial views, or components existed.

Typical uses (very real 2000–2010 patterns):

  • Header (logo, navigation menu, CSS links)
  • Footer (copyright, contact info, tracking scripts)
  • Database connection string & open/close code
  • Common functions / Subs (format currency, validate email, send email)
  • Sidebar (categories, latest news, ads)
  • Top banner or login status bar

Without includes, you would have to copy-paste the same header/footer code into every single .asp file — nightmare to maintain.

2. The Two Syntaxes You Must Know

Classic ASP supports two slightly different include directives — both do the same thing, but one is more common.

Directive Syntax Example Most common in real code? Notes
<!– #include file=”…” –> <!– #include file=”header.inc” –> ★★★★★ (by far the most used) Relative to current file
<!– #include virtual=”…” –> <!– #include virtual=”/includes/header.inc” –> ★★★☆☆ Relative to site root (/)

Rule of thumb (what most developers followed):

  • Use file= for includes in the same folder or subfolder
  • Use virtual= for includes from the root (especially in larger sites)

3. Basic Example – Header & Footer Include

File: header.inc

asp

File: footer.inc

asp
</main>

<footer>
<p>© <%= Year(Now()) %> <%= Application("CompanyName") %>. All rights reserved.</p>
<p>Contact: <%= Application("SupportEmail") %> | Phone: <%= Application("SupportPhone") %></p>
</footer>

</body>
</html>

Any page (e.g. products.asp):

asp

Result: Every page automatically gets the same header (with dynamic login status) and footer (with current year) — change once in .inc file → all pages update.

4. Real-World Example – Database Connection Include

File: db_connection.inc (very common pattern)

asp

Then in any page:

asp

5. Important Rules & Best Practices (2026 Perspective)

  • File extension: .inc is convention (include), but can be .asp too
  • Never put sensitive data (passwords, connection strings) in includes without protection → Real sites used separate config files outside web root or encrypted
  • Security warning: Includes are processed server-side — browser never sees them But if someone guesses /includes/db_connection.inc → they can download it unless IIS is configured to block .inc files → Best practice: rename to .asp or use IIS request filtering to deny .inc
  • Performance: Includes are fast — no extra overhead
  • Global.asa can also include files (rare but possible)

6. Teacher Summary – ASP Including Files in Classic ASP

ASP Including Files means:

  • Insert content of another .asp / .inc file at runtime with <!– #include file=”…” –> or virtual=”…”
  • Main use: header, footer, navigation, DB connection, common functions
  • Lets you change shared code once → all pages update
  • file= = relative to current file
  • virtual= = relative to site root (/)
  • Very typical pattern: <!– #include file=”header.inc” %> at top + footer.inc at bottom
  • Always use Server.HTMLEncode on dynamic content from includes
  • Protect .inc files — IIS should block direct access

This is how millions of Classic ASP sites stayed maintainable — one header change → entire site updates — and many legacy Indian small-business, internal, government, and ERP systems still use exactly this include pattern in 2026.

Next class?

  • Want a full site skeleton example with header + footer + DB include?
  • Or how to protect .inc files from direct download?
  • Or compare Classic ASP #include vs Razor @RenderPage / layouts?
  • Or move to the next W3Schools topic (ASP Cookies again or ASP Sessions)?

Just tell me — I’m here! 🚀🇮🇳 Keep learning strong, Webliance! 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *