The impact of the include file on the database link

Source: Internet
Author: User
Tags configuration settings contains database join html tags include insert parent directory relative
Links | data | Database did you notice that when you use the Mx/ud development program, all pages that need to link to the database use the include file to invoke the database link file at the beginning of the page, such as:
<!--#include file= "connections/con123456.asp"-->
So what does this code have to study? Of course there is research, if you do not use it correctly, then perhaps you debug the local normal program, once uploaded to the server on the error, a possible reason is to include files in the mischief! Let's take a look at what contains files:

Include file
Full name: Server_side include, from the names of a look at it should be the server-side contains files, referred to as SSI.
SSI provides a way for users to insert the contents of a file into another file before the WEB server processes it. The ASP uses only the #include instructions for this mechanism. To insert a file in an. asp file, use the following syntax:
<!--#include Virtual | FILE = "FileName"-->
The virtual and file keywords indicate the type of path that is used to contain the file, and filename is the path and name of the file that you want to include.
The included file does not require a special file name extension, but it is a good programming practice to assign the. inc extension to the included file to differentiate it from other types of files. Since most virtual hosting providers do not set up an inc explanation, if you fill in the. inc file address, it will be displayed directly in the browser source code. Therefore, it is strongly recommended that you change the suffix to. asp when using include database join files and files that include ASP source code

Virtual keyword
Use the virtual keyword to indicate that the path starts with the virtual directory. For example, if a file named Footer.inc belongs to a virtual directory named/myapp, the following row inserts the contents of Footer.inc into the file containing the row:
<!--#include virtual = "/myapp/footer.inc"-->

File keyword
Use the file keyword to indicate that a relative path is used. The relative path begins with the directory containing the containing file. For example, if your file is in the directory Myapp and the file Header1.inc is in Myapp\headers, the following line inserts Header1.inc into your file:
<!--#include file = "Headers/header1.inc"-->
Note that the path to the contained file headers/header1.inc is relative to the containing file, and if the script containing the #include statement is not in the/myapp directory, then the statement will not work.
Special NOTE: If the Enable upper-level directory option is selected in Internet Services Manager, you can also use the file keyword and the ... /syntax contains the parent directory, which is the file in the previous level directory.
However, in general, for security reasons, Web space service providers when setting up the server, the "enable the upper-level directory" option is prohibited, and you use Mx/ud to develop and debug the program on the local machine, all the pages that need to link the database, Will call the database link file with the include file at the beginning of the page, for example:
<!--#include file= "connections/con123456.asp"-->
If you do not consider the "Include parent directory" issue, the page may appear:
<!--#include file= ". /connections/con123456.asp "-->
Similar form, in the local database link is normal (set up the virtual directory locally, "enable the upper level directory" option is selected by default), upload to the server will be error, this is a beginner ud/mx to develop dynamic Web site, especially without the ASP based on the direct use of ud/ MX Learning dynamic Development Technology of friends are easily overlooked places. The best approach is to turn the Enable upper-layer Directory option off (disabled) when you are debugging your program locally to get the same development environment on the remote server.

Set the method as follows:
Start IIS Manager, view the virtual directory/Site properties you have set up, and click the home directory or virtual Directory tab in the pop-up Properties panel, as follows:

Click [Configure ...] in the Application Settings section. button, eject the application configuration settings panel, as shown below:

Click the "Application Options" tab to remove the "Enable parent directory" checkmark. Click the OK button to return.

The location of the included file
The included files can be in a directory within your Web site, or outside your Web site. Typically, you should make the included files in the directory of your Web site. If a included file is located within your Web site, the next time the browser requests the include file, the changes to the included file are displayed. However, if the included file is outside your Web site, this change will not be reflected until the ASP application restarts or the Web server restarts. The ASP detects changes to any include files in the application's namespace (in the application's starting directory).

Include files: Hints and warnings
A included file can also contain other files. If the #include instruction does not cause a loop, an. asp file can include the same file multiple times. For example, if the file first.asp contains a file second.inc, then second.inc must no longer contain first.asp. A file cannot contain itself. The ASP detects such loops or nesting errors, generates an error message when detected, and stops processing the requested. asp file.
ASP contains files before executing script commands. Therefore, you cannot use script commands to create the name of the included file. For example, the following script will not open Header1.inc because the ASP executes #include instructions before it assigns a filename to the variable name.
<!--This script would fail-->
<% name= (Header1 & ". Inc")%>
<!--#include file= "<%= name%>"-->
Script commands and procedures must be fully contained in script delimiters <% and%>, HTML tags <SCRIPT> and </SCRIPT> or HTML tags <OBJECT> and </OBJECT>. In other words, you cannot open a script delimiter in an. asp include file, and then close the delimiter in a contained file; the script or script command must be a complete unit. For example, the following script will not run:
<!--This script would fail-->
<%
For i = 1 to n
Statements in main file
<!--#include file= "Header1.inc"-->
Next
%>
The following script will work correctly:
<%
For i = 1 to n
Statements in main file
%>
<!--#include file= "Header1.inc"-->
<% Next%>

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.