Tuesday, August 4, 2009

How to get Current Page Url

in asp sometime we required current page URL, if u r using JavaScript then u can easily get it by using location.href or one way is HTTP_REFEREL but it will give you Previous page name

now look at here how we can get the Current page URL


< %

function pageurl()

serverName = Request.ServerVariables("SERVER_NAME")
ScriptName = Request.ServerVariables("SCRIPT_NAME")

if Request.ServerVariables("HTTPS") = "on" then secure = "s"

prt = strleft(LCase(Request.ServerVariables("SERVER_PROTOCOL")), "/") & secure

if Request.ServerVariables("SERVER_PORT") = "80" then
port = ""
else
port = ":" & Request.ServerVariables("SERVER_PORT")
end if

pageurl = prt & "://" & serverName & port & ScriptName

end function

%>


Here is a function which will generate pageurl to call this use


<% response.write (pageurl) %>


if page had Querystring you can also retrive that like this


< %
Qstring = Request.ServerVariables("QUERY_STRING")
response.write(pageurl() & "?" & Qstring )
% >


hope it will helps you.

1 comment: