Realize universal absolute path generation method in ASP

zhaozj2021-02-08  198

Home: www.maxss.net mail: maxchou@163.com

When I develop ASP Access web applications, there will be a positioning problem of database file path. If you can specify things directly when you implement it on your computer, if you do the project to upload to other servers or move other machines, you must change this path every time you change this path. Here, in connection with the experience of me to do this website, let us "one for all". After using the server.mappath ("file.asp") statement in the ASP, the absolute path on the local drive is returned, such as "D: /MysISITE/test/file.asp, so in different subdirects Different files use this statement to return the path where the file is located so that we cannot use this statement to solve the above problems, but as long as this method and other character functions can be easily solved. problem. Now, your site directory structure is as follows: mysite | - db | - db1.mdb | - db2.mdb | - sub_folder | - Hello.asp | - search.asp | - index.asp As long as we need access to the database ASP file Add the following statement:

IF session ("rootdir") = "" "" ""

DIM STR

Str = server.mappath ("db")

Session ("rootdir" = MID (STR, 1, INSTR (1, Str, "MySite", 1) - 1) & "mysite / dB"

END IF

...

Set conn = server.createObject ("adoDb.connection")

Conn.open "Driver = {Microsoft Access Driver (* .mdb)}; dbq =" & session ("rootdir") & "/db1.mdb" & "; pwd =" & pw

This stores the extracted path of your site neutral directory "DB" in Session ("rootdir"). If you change your site's home directory or move to another machine, you can do not need to pay for the database file. Take the path problem.

转载请注明原文地址:https://www.9cbs.com/read-2157.html

New Post(0)