Find the Current URL in ASP

The full URL to a page comes in three parts: The domain name, the path to the file then the filename, and the QueryString. For example, take the URL The three parts of this are:

  1. The domain name:
  2. The path to the page: /example/page.asp
  3. The QueryString: name=Bob

So how do you find it all out with your own scripts?

Well the following code should do it:

Dim strDomain, strPath, strQueryString, strURL
 find out the domain:
strDomain = Request.ServerVariables("HTTP_HOST")
 find out the path to the current file:
strPath = Request.ServerVariables("URL")
 find out the QueryString:
strQueryString = Request.ServerVariables("QUERY_STRING")
 put it all together:
strURL = "http://" & strDomain & strPath & "?" & strQueryString
Response.Write "The current URL is: " & strURL


The latest posts sent straight to your inbox.