Many of my friends are on the Server. cnbruce is also repeated over and over again on the Ath, but it still cannot be completely solved. So I hope more friends will be enlightened and clear through the example below.
First look at the figure:
1. First, on the local machineElastic Block StorageCreateRed folder, Keep creating in the clipConn. asp fileThe file content is as follows:
<% = Server. Mappath ("database/cnbruce. mdb") %> <% = Server. Mappath ("/database/cnbruce. mdb") %> <% = Server. Mappath ("../database/cnbruce. mdb") %> |
The final result of the three main debugging paths is displayed.
2.Red folderCreateFolder databaseThe clip contains the cnbruce. mdb file.
Therefore, we are sure that the absolute path of the database file is:E:/red/database/cnbruce. mdb
There should be no problem with the above. Continue to look at it clearly. If you don't understand it, learn the windows OS -_-!
3. For comparison, continueRed folderCreateBlue folderThe clip is stored in the sameConn. asp file
<% = Server. Mappath ("database/cnbruce. mdb") %> <% = Server. Mappath ("/database/cnbruce. mdb") %> <% = Server. Mappath ("../database/cnbruce. mdb") %> |
4. Of course, it is very importantRed folderSet the virtual directory. The method is inRed folderRight-click and select "share...". In the pop-up window, select the "Web Sharing" label, select "share this folder", and set the alias to"Red". Finally, click "OK ".
5. OK. Now you can debug two conn. asp files.
First look at the red folder. The entered URL should be:Http: // localhost/red/conn. asp
Only one of the viewing results is correct, that is
<% = Server. Mappath ("database/cnbruce. mdb") %>
6. Check the URL in the blue folder under the red folder:Http: // localhost/red/blue/conn. asp
The observation result is still correct, that is
<% = Server. Mappath ("../database/cnbruce. mdb") %>
7. To sum up, why do not the same code display the correct path twice?
Obviously, this is because of the relative path. The conn. asp file in the red folder has a sibling relationship with the database folder, so you can directly find cnbruce. mdb.Database/cnbruce. mdb
The conn. asp and database folders in the blue folder are in the uncle's relationship. To find cnbruce. mdb, of course it is../Database/cnbruce. mdb, Where../Is to the upper layer.
8. Check again.<% = Server. Mappath ("/database/cnbruce. mdb") %>Both display the same effect and pointC: \ inetpub \ wwwroot \Next, it is because "database" is added before"/", Indicates that the root directory is reached, and the local IIS virtual root directory isC: \ inetpub \ wwwroot \InDefault Web site properties.
9. Check again! It's always on the local device. How is it uploaded to the network?
First, you must be aware of the address relationship between the conn. asp connection file and the *. mdb database file.
Then, select the correct Server. Mappath conversion method.
We recommend that you do not use"/"Path. This involves the issue of virtual hosts and non-virtual hosts.
The so-called virtual host, such as my own site, its virtual root directory is the root directory of the website itself, there is no problem of switching to c: \ inetpub \ wwwroot.
Debuggable
Http://www.cnbruce.com/red/conn.asp
Http://www.cnbruce.com/red/blue/conn.asp
We can see that"/"The path is the root address of this site.
10. Be sure to pay attention to it!
The long journey has reached the end, and you must support anything you say ~!
Although we know how to write the conn. asp file content, we should pay attention to include the essence of the file When referencing it:The contained file is displayed in the contained file..
Therefore, no matter where conn. asp is put, regardless of the content of conn. asp, it depends onThe relationship between the file location and the database location that contains the file.