你如何使用ASP经典当前虚拟目录的名称? [英] How do you get the name of the current virtual directory using ASP Classic?
问题描述
你如何使用ASP经典当前虚拟目录的名称?在ASP.NET中,您可以使用 Request.ApplicationPath
找到这个。
How do you get the name of the current virtual directory using ASP Classic? In ASP.NET you can use Request.ApplicationPath
to find this.
例如,假设你有一个这样的网址:
For example, let's say you have a URL like this:
http://localhost/virtual_directory/subdirectory/file.asp
在ASP.NET中, Request.ApplicationPath
将返回 / virtual_directory
In ASP.NET, Request.ApplicationPath
would return /virtual_directory
推荐答案
您可以从多个服务器变量之一获取该文件的虚拟路径 - 尝试之一:
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)
Request.ServerVariables("PATH_INFO")
Request.ServerVariables("SCRIPT_NAME")
(而不是 INSTANCE_META_PATH
为previously建议 - 这让你的元基本路径,而不是你期望的虚拟路径)。
(but not INSTANCE_META_PATH
as previously suggested - this gives you the meta base path, not the virtual path you're expecting).
无论是服务器变量会给你的虚拟路径包括任何子目录和文件名 - 给你的榜样,你会得到/virtual_directory/subdirectory/file.asp。如果你只是想在虚拟目录,你需要使用任何方法,你preFER拔除目录出来的路径,如第二个斜杠后去掉一切:
Either server variable will give you the virtual path including any sub-directories and the file name - given your example, you'll get "/virtual_directory/subdirectory/file.asp". If you just want the virtual directory, you'll need to strip off everything after the second forward slash using whatever method you prefer for plucking a directory out of a path, such as:
s = Request.ServerVariables("SCRIPT_NAME")
i = InStr(2, s, "/")
If i > 0 Then
s = Left(s, i - 1)
End If
或
s = "/" & Split(Request.ServerVariables("SCRIPT_NAME"), "/")(1)
这篇关于你如何使用ASP经典当前虚拟目录的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!