The server-side include directive instructs the Web server to insert the content of another file into this file before processing it. It can be used to include headers, footers, and other elements that will be reused on multiple pages.
Use the following syntax to insert a file into an .asp file.
<!-- #include virtual="filename" -->
<!-- #include file="filename" -->
The virtual or file keyword indicates the type of path you are using to include the file, and <i>filename</i> is the path and file name of the file you want to include. An included file does not require a special file name extension, however some coders give include files the .inc extension to distinguish them from other types of files.
For better security, it is advisable to place include files in a separate directory, such as \includes. By default, Web server Read permissions are applied to all files. However, to prevent users from viewing the contents of your include files, you should disable Read permissions for the Include directory.
Insert the include directive in your webpage at the point where you want the include file code to be placed. An example is shown below.
<!DOCTYPE html> <html lang="en"> <head> </head> <body> <!-- #include file="../includes/header.inc" --> <h1>Title</h1> <p>This is the text of your webpage, the include file directive above inserts code that is used in all webpages of the website to create a header. The include file directive below inserts an include file that is used all webpages of the website to create a footer.</p> <!-- #include file="../footer.inc" --> </body> </html>
An include file can contain html code, style code, or VBScript code just like a regular webpage, except it doesn/t really need the .asp file extension because the file that it is included in will already have that file extension. Below is an example of the contents of a small include file.
<p>The current system time is: </p> <% response.write(Time) %>