如何使用ASP Classic获取当前虚拟目录的名称?在ASP.NET中,您可以使用Request.ApplicationPath
来找到它。如何使用ASP Classic获取当前虚拟目录的名称?
例如,假设你有一个这样的URL:
http://localhost/virtual_directory/subdirectory/file.asp
在ASP.NET中,Request.ApplicationPath
将返回/virtual_directory
如何使用ASP Classic获取当前虚拟目录的名称?在ASP.NET中,您可以使用Request.ApplicationPath
来找到它。如何使用ASP Classic获取当前虚拟目录的名称?
例如,假设你有一个这样的URL:
http://localhost/virtual_directory/subdirectory/file.asp
在ASP.NET中,Request.ApplicationPath
将返回/virtual_directory
您可以从多个服务器变量之一获取该文件的虚拟路径 - 尝试之一:
Request.ServerVariables("PATH_INFO")
Request.ServerVariables("SCRIPT_NAME")
(但不是INSTANCE_META_PATH
,如以前所建议的那样 - 这会为您提供元基本路径,而不是您期望的虚拟路径)。
两个服务器变量都会为您提供虚拟路径,包括任何子目录和文件名 - 根据您的示例,您将获得“/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
或:
s = "/" & Split(Request.ServerVariables("SCRIPT_NAME"), "/")(1)
尝试使用:Request.ServerVariables( “SCRIPT_NAME”)
或尝试使用Request.ServerVariables(“INSTANCE_META_PATH”),如果这不适合你。
对于其他的服务器变量列表尝试此链接: