How ASP Gets the URL of the current page

Source: Internet
Author: User

Sometimes, you may want to get the current page's URL in a browser window to display the URL. For example, if you want your visitors to submit a blog post to Digg you need to get the exact same URL. There are many other reasons too. Here's how you can do that.

The following code is added to the page:

<%
function Curpageurl ()
Dim s, Protocol, port

If Request.ServerVariables ("HTTPS") = "on" Then
s = "S"
Else
s = ""
End If

protocol = Strleft (LCase (Request.ServerVariables ("Server_protocol")), "/") & S

If Request.ServerVariables ("server_port") = "Then"
Port = ""
Else
Port = ":" & Request.ServerVariables ("Server_port")
End If

Curpageurl = protocol & "://" & Request.ServerVariables ("SERVER_NAME") &_
Port & Request.ServerVariables ("Script_name")
End Function

function Strleft (STR1,STR2)
Strleft = Left (Str1,instr (STR1,STR2)-1)
End Function
%>

Now you can get the URL of the current page to use the line

<%
Response.Write (Curpageurl ())
%>
If your page has a string of information you want to query and you can try this code:

<%
Response.Write (Curpageurl () & "?" & Request.ServerVariables ("Query_string")
%>
The following example shows how to do this:
<%
function Curpagename ()
Dim pagename

PAGENAME = request.servervariables ("Script_name")

If inStr (pagename, "/") > 0 Then
pagename = right (pagename, Len (pagename)-instrrev (PAGENAME, "/")
End If

Curpagename = pagename
End Function

Response.Write ("The current page name is" & Curpagename ())
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.