如何使用ASP而不是ASP.net获取root url? 我发现这个问题( How do I get the site root URL? )如何使用ASP而不是ASP.net获得root url
,但它关系到ASP.net。
=====================================
阿巴斯的回答给我的
父站点根URL
,但不提供我的子网站根URL
========================= ============
如何使用ASP而不是ASP.net获取root url? 我发现这个问题( How do I get the site root URL? )如何使用ASP而不是ASP.net获得root url
,但它关系到ASP.net。
=====================================
阿巴斯的回答给我的
父站点根URL
,但不提供我的子网站根URL
========================= ============
传统的ASP有一个Request.ServerVariables集合,其中包含所有服务器和环境的详细信息LS。下面是该示例.NET代码的传统的ASP版本是这样的:
function getSiteRootUrl()
dim siteRootUrl, protocol, hostname, port
if Request.ServerVariables("HTTPS") = "off" then
protocol = "http"
else
protocol = "https"
end if
siteRootUrl = protocol & "://"
hostname = Request.ServerVariables("HTTP_HOST")
siteRootUrl = siteRootUrl & hostname
port = Request.ServerVariables("SERVER_PORT")
if port <> 80 and port <> 443 then
siteRootUrl = siteRootUrl & ":" & port
end if
getSiteRootUrl = siteRootUrl
end function
如果我网站的URL是http://parentSite/subsite/default.asp,以上是否将http:// parentSite/subsite作为根网址? – Hoque 2011-12-22 07:52:18
我已将.NET代码转换为经典ASP,因此它将执行示例中代码的操作。如果您的网站未使用SSL并使用端口80,则上面的代码将显示:http:// parentSite/subsite。理解它的最好方法就是运行它并与它一起玩。这很简单,如果遇到困难,你可以在这里发布。 – Abbas 2011-12-22 07:58:01
我已经测试过,它不会去子网站 – Hoque 2011-12-22 08:41:33
这应该得到你想要的东西。
getSiteURL()
Function getSiteURL()
port = "http"
https = lcase(request.ServerVariables("HTTPS"))
if https <> "off" then prot = "https"
domainname = Request.ServerVariables("SERVER_NAME")
filename = Request.ServerVariables("SCRIPT_NAME")
querystring = Request.ServerVariables("QUERY_STRING")
fullpath = port & "://" & domainname & Request.ServerVariables("SCRIPT_NAME")
filename = right(fullpath, InStr(StrReverse(fullpath), StrReverse("/")))
url = Replace(fullpath, filename, "/")
response.write url & "<br>"
end Function
不,它没有。它提供了我调用该函数的url部分。例如,如果我从这个页面parentSite/childsite/Folder/Default.asp调用函数,它会返回parentSite/childsite /文件夹 – Hoque 2011-12-26 01:09:54
,那么我想我不确定你想要什么?我发布的内容将返回到您所在页面的路径。页面上的功能是否与要显示的页面不同?您将在哪个页面上获取URL?您可能必须将信息传递给该功能才能使用它。 – Robert 2011-12-26 01:29:49
想要将parentSite/childSite作为子网站的根网址 – Hoque 2011-12-26 01:31:18
的可能重复[RESOLVEURL/Url.Content在传统的ASP等效(http://stackoverflow.com/questions/7963635/resolveurl-url-content-equivalent-in-classic-asp) – 2011-12-24 16:46:36