开发者

How can I get the current domain in Classic ASP?

I want to get the current domain so if th开发者_C百科e page is http://www.domain.com/page.asp I need www.domain.com


Request.ServerVariables("SERVER_NAME")'

To be complete, one of my functions:

  function PageUrl
     dim sPort
     sPort = Request.ServerVariables("SERVER_PORT")
     if sPort = "80" then
        sPort = ""
     else
        sPort = ":" & sPort
     end if

     PageUrl = "http://" & Request.ServerVariables("SERVER_NAME") & sPort & _
                           Request.ServerVariables("URL") & "?" & _
                           Request.ServerVariables("QUERY_STRING")
  end function


One of the Request Servervariables (server_name?)

http://www.w3schools.com/asp/coll_servervariables.asp


Put this before the end of your function to remove the ? when there is no querystring element, as a random ? at the end may not be what you want:

If right(PageUrl,1)="?" then PageUrl = left(PageUrl,len(PageUrl)-1)


<%
for each x in Request.ServerVariables
response.write(x&"="&Request.ServerVariables(x)&"<br>")
next
%>

This will gives you results like this with all Request.ServerVariables

REMOTE_ADDR = 40.20.170.160
REMOTE_HOST = 40.20.170.160
REMOTE_USER = 
REQUEST_METHOD = GET
SCRIPT_NAME = /xyz/get.asp
SERVER_NAME = www.xyz.com
SERVER_PORT = 80
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜