如何确定网站是否设置为虚拟目录?

时间:2011-10-17 09:29:14

标签: asp-classic

我有这个经典的asp代码:

'code start
https = lcase(request.ServerVariables("HTTPS")) 
if https <> "off" then prot = "https" else prot ="http"

'use the following for website (non-virtual)
TheURL1 = prot&"://"&Request.ServerVariables("SERVER_NAME")&"/"

'use the following for virtual directory website
TheURL2 = prot&"://"&Request.ServerVariables("SERVER_NAME")&"/Tawanda/NewTawanda/"
'code end

我用它来确定根URL(例如http://myserver/)但我注意到当网站配置为虚拟目录时,如果它不是虚拟目录,我必须使用TheURL2和TheURL1。

我的问题是如何确定(在经典asp中)网站是否配置为虚拟目录,以便我可以将此代码放在if... then...语句中?

1 个答案:

答案 0 :(得分:0)

您可以查询 APPL_MD_PATH 的ServerVariables值。

当您运行不在虚拟目录(常规网站)下的应用程序时,该值应以 ROOT 结束,如果不是,则表示您位于虚拟目录中。

试试这个:

' Check value of APPL_MD_PATH
If Request.ServerVariables("APPL_MD_PATH").EndsWith("/ROOT") Then
     'use the following for website (non-virtual)
     TheURL1 = prot&"://"&Request.ServerVariables("SERVER_NAME")&"/"
Else
     'use the following for virtual directory website
     TheURL2 = prot&"://"&Request.ServerVariables("SERVER_NAME")&"/Tawanda/NewTawanda/"
End If
'code end