0

抱歉,如果在其他地方回答了这个问题,但我尝试搜索了几页但没有成功。

所以我有一个包含文件(侧边栏),我在所有页面中都使用它。

Default.asp
Products.asp
Salary/Survey.asp
inc/sidebar.asp (this is the included file)

现在里面sidebar.asp我有一个链接Salary/Survey.asp

从根级别的所有其他页面,我可以简单地使用href='Salary/Survey.asp'并且可以正常工作。但是当我在页面上时Survey.asp,写作href='Salary/Survey.asp'会变成现实Salary/Salary/Survey.asp。我知道必须../Salary/Survey.asp正确使用它,但它不适用于根级别页面。

我不能使用root relativewhich is/Default.asp并且/Salary/Survey.asp因为我正在为其他人的项目工作并且我不知道他的目录结构,因此我只能选择document relative路径。

希望这很清楚,有人帮助我。

谢谢!

4

3 回答 3

2

我们通过以下方式解决了这个问题......

  1. 我们的每个 asp 页面都包含一个特殊文件,用于对全局变量进行调和设置。我们称我们为 Info.asp
  2. Info.asp 中,我们定义了一个名为strRelativePath
    Dim strRelativePath
    strRelativePath = ""的变量
  3. 每个asp页面根据它的相对位置设置相对路径:

例如:

  • 根页面 - strRelativePath = ""
  • 一级深页 - strRelativePath = "../"
  • 两级深页面 - strRelativePath = "../../"

然后就是在所有需要相对路径的链接前面加上 <%= strRelativePath %>

于 2012-03-31T13:41:02.217 回答
1
you need to get write this after the that - Salary/Survey.asp
You can get the virtual path to the file from one of several server variables - try either:

Request.ServerVariables("PATH_INFO")
Request.ServerVariables("SCRIPT_NAME")

任一服务器变量都会为您提供包括任何子目录和文件名的虚拟路径 - 给出您的示例,您将获得/virtual_directory/subdirectory/file.asp. 如果您只想要虚拟目录,则需要使用您喜欢从路径中提取目录的任何方法在第二个正斜杠之后剥离所有内容,例如:

s = Request.ServerVariables("SCRIPT_NAME")
i = InStr(2, s, "/")
If i > 0 Then
    s = Left(s, i - 1)
End If
or:

s = "/" & Split(Request.ServerVariables("SCRIPT_NAME"), "/")(1)
于 2012-03-31T18:33:51.570 回答
0

基本上,如果您的侧边栏可以包含在不同文件夹中的程序中,那么唯一“简单”的方法就是使用您提到的绝对路径。

你说不能用,所以我会想不同的方法...

  • 虚拟文件夹:在 IIS 中,您可以在薪水文件夹中为“薪水”设置一个虚拟文件夹,并将其指向站点的根目录。
  • 操作系统链接(类似于上面,但在操作系统级别)
  • 使用地图路径。您可以检查 mappath 以查看您所在的实际文件夹,并使用正确的包含(带/不带 /salary)虽然我认为这可能会给您一个错误,不确定。
于 2012-03-23T17:30:34.223 回答