Αναφορά Αρχείων ASP
- Προηγούμενη Σελίδα Προγραμματισμός ASP
- Επόμενη Σελίδα Global.asa ASP
Η εντολή #include χρησιμοποιείται για τη δημιουργία συνεχόμενων σελίδων που απαιτούν επαναχρησιμοποιούμενα συνάρτηματα, κεφαλίδες, πίσω πόρτες ή άλλες στοιχεία.
Εντολή #include
Με τη χρήση της εντολής #include, μπορούμε να εισάγουμε έναν άλλον φάκελο ASP πριν την εκτέλεση του ASP αρχείου από τον διακομιστή. Η εντολή #include χρησιμοποιείται για τη δημιουργία συνεχόμενων σελίδων που απαιτούν επαναχρησιμοποιούμενα συνάρτηματα, κεφαλίδες, πίσω πόρτες ή άλλες στοιχεία.
Πώς να χρησιμοποιήσουμε την εντολή #include
Υπάρχει ένα αρχείο με το όνομα "mypage.asp":
<html> <body> <h2>Φράσεις Μудρίας:</h2> <p><!--#include file="wisdom.inc"--></p> <h2>The time is:</h2> <p><!--#include file="time.inc"--></p> </body> </html>
Αυτό είναι ο φάκελος "wisdom.inc":
Δεν πρέπει ποτέ να αυξάνουμε πέρα από ό,τι είναι απαραίτητο; το αριθμό των οντοτήτων που απαιτούνται για να εξηγήσουμε κάτι.
Αυτό είναι ο φάκελος "time.inc":
<% Response.Write(Time) %>
Η πηγή κώδικα που βλέπετε στον περιηγητή πρέπει να μοιάζει με αυτό;
<html> <body> <h2>Φράσεις Μудρίας:</h2> Δεν πρέπει ποτέ να αυξάνουμε πέρα από ό,τι είναι απαραίτητο; the number of entities required to explain anything."</p> <h2>The time is:</h2> <p>11:33:42 AM</p> </body> </html>
The syntax for including files:
To reference a file in ASP, place the #include command within the comment tags:
<!--#include virtual="somefilename"-->
Or:
<!--#include file ="somefilename"-->
Keyword Virtual
The keyword virtual indicates that the path starts with the virtual directory.
If the "header.inc" file is located in the virtual directory /html, the following line of code will insert the content of the file "header.inc":
<!-- #include virtual ="/html/header.inc" -->
Keyword File
The keyword File indicates a relative path. The relative path starts with the directory containing the referencing file.
Assuming the file is located in the subfolder headers of the html folder, the following code can reference the content of the "header.inc" file:
<!-- #include file ="headers\header.inc" -->
Note:The path of the referenced file is relative to the referencing file. If the file containing the #include statement is not in the html directory, this statement will not take effect.
You can also use the keyword file and syntax (..\) to reference files in the parent directory.
Tips and comments
In the previous section, we use ".inc" as the suffix for referenced files. Note: If the user tries to directly browse the INC file, the content of the file will be exposed. If the content of the referenced file involves secrets, it is better to use ".asp" as the suffix. The source code in ASP files is compiled and not visible. Referenced files can also reference other files, and an ASP file can reference the same file multiple times.
Important note:The referenced file is processed and inserted before the script is executed.
The following code cannot be executed because ASP executes the #include command before assigning values to variables:
<% fname="header.inc" %> <!--#include file="<%=fname%>"-->
Cannot contain file references within script delimiters:
<% For i = 1 To n <!--#include file="count.inc"--> Next %>
Αλλά αυτό το σενάριο μπορεί να λειτουργήσει:
<% For i = 1 to n %> <!--#include file="count.inc" --> <% Next %>
- Προηγούμενη Σελίδα Προγραμματισμός ASP
- Επόμενη Σελίδα Global.asa ASP