ASP Tutorial: Learn how to master ASP file references

Source: Internet
Author: User
Tags count header include parent directory relative
Tutorial

#include命令用于在多重页面上创建需重复使用的函数, headers, footers, or other elements.

#include command

By using the #include command, we can insert another ASP file into this file before the server executes an ASP file. #include命令用于在多重页面上创建需重复使用的函数, headers, footers, or other elements.

How to use the #include command

Here is a file called "mypage.asp":

This is the "wisdom.inc" file:

"One should never increase, beyond what is necessary,the number of entities required to explain anything."

This is the "time.inc" file:

<%response.write (Time)%>

The source code viewed in the browser should look like this:


Syntax for including files:

To refer to the file in ASP, place the #include command in the Comment tab:

<!--#include virtual= "Somefilename"-->

Or:

<!--#include file = "Somefilename"-->

Keyword virtual

The keyword virtual indicates the path that is located in the virtual directory.

If the name "Header.inc" is in a virtual directory named/html, the following line of code inserts the contents of the file "Header.inc":

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

Keyword file

The keyword file can indicate a relative path. The relative path starts with the directory that contains the referenced file.

Suppose a file is in the subfolder headers of an HTML folder, and the following code refers to the contents of the "Header.inc" file:

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

Note: The path to the referenced file is relative to the referencing file. This declaration is not valid if the file containing the #include declaration is not in the HTML directory.

You can also use the keyword file and syntax (... \) to refer to files in the parent directory.

Tips and comments

In the above section, we use ". Inc" as the suffix of the referenced file. Note: If a user tries to navigate directly to an inc file, the contents of the file are exposed. If the content in the referenced file involves confidentiality, it is best to use the "ASP" suffix. The source code in the ASP file is not visible when it is compiled. Referenced files can also refer to other files, and ASP files can refer to the same file multiple times.

Important: The referenced file is processed and inserted before the script executes.

The following code cannot be executed because ASP executes the #include command before assigning a value to a variable:

<%fname= "Header.inc"%><!--#include file= "<%=fname%>"-->

You cannot include a file reference between script delimiters:

<%for i = 1 to n  <!--#include file= "Count.inc"-->next%>

But this script can work:

<% for i = 1 to n%><!--#include file= "count.inc"--><% Next%>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.