首页 > 解决方案 > Server.Execute 使用固定路径

问题描述

我正在尝试server.execute()通过虚拟函数库 ( <!-- #include virtual="lib/functions.asp"-->) 中的包含来实现,我可以从系统中的任何子文件夹调用它。我正在尝试实现一个新功能,该功能应该存在于我们系统中的所有页面上,而将其手动添加到每个页面几乎是不可行的。而且我需要以一种不会干扰任何页面上的代码的方式实现它,这就是为什么我将它作为server.execute()一个虚拟库来执行的原因,我知道它已经存在于系统中的任何地方。

例如:

'location of routine.asp = https://example.com/admin/routine/routine.asp

Server.Execute("routine/routine.asp")
'Will work if I add the virtual lib from an ASP-page in the admin subfolder, but not if I call it from another subfolder

Server.Execute("https://example.com/admin/routine/routine.asp")
'Does not work, because server.execute can't handle that kind of fixed path

文档明确指出不允许使用冒号和双斜杠,但我不知道如何确保文件的执行发生在系统中的哪个位置调用。

问题:如何使server.execute(path)'s path 处理固定路径,或动态更改路径以确保始终可以正确定位文件?

标签: vbscriptasp-classic

解决方案


如果您想使用绝对路径,请确保您使用的是绝对路径(从根目录开始的完整路径)。

认为您只需要明确指定绝对路径;

Server.Execute("/admin/routine/routine.asp")

推荐阅读