« Find a visitor's IP Address in ASP | Main | How to use the QueryString in ASP »

How to 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 http://www.example.com/example/page.asp?name=Bob. The three parts of this are:

1. The domain name: www.example.com
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:

<%@language="VBScript"%>
<%
  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
%>

Related Entries

How to use the QueryString in ASP - Oct 19, 2005

Find a visitor's IP Address in ASP - Oct 19, 2005

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Adlinks

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.2