Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classic ASP - get full url name

Tags:

asp-classic

Im wondering if someone could help me.

I have the following URL ( which is dynamic )

www.website.com/images/gal/boxes-pic004.asp

How can i extract the 'boxes-pic004' part using classic ASP

Thanks

like image 735
BigJobbies Avatar asked Sep 05 '13 09:09

BigJobbies


4 Answers

<%
Dim sScriptLocation, sScriptName, iScriptLength, iLastSlash

sScriptLocation = Request.ServerVariables("URL")
iLastSlash      = InStrRev(sScriptLocation, "/")
iScriptLength   = Len(sScriptLocation)
sScriptName     = Right(sScriptLocation, iScriptLength - iLastSlash)
%>

sScriptName will then contain boxes-pic004.asp, then you can use Replace(sScriptName, ".asp", "") to remove the extension as well.

like image 72
stealthyninja Avatar answered Sep 29 '22 06:09

stealthyninja


Just you can try to output all ServerVariables like,

Eg Page Url: https://www.google.com/gmail/inbox.asp?uid=1421&skyid=2823595

Dim strProtocol
Dim strDomain
Dim strPath
Dim strQueryString
Dim strFullUrl

If lcase(Request.ServerVariables("HTTPS")) = "on" Then 
    strProtocol = "https" 
Else
    strProtocol = "http" 
End If

strDomain= Request.ServerVariables("SERVER_NAME")
strPath= Request.ServerVariables("SCRIPT_NAME") 
strQueryString= Request.ServerVariables("QUERY_STRING")

strFullUrl = strProtocol & "://" & strDomain & strPath
If Len(strQueryString) > 0 Then
   strFullUrl = strFullUrl & "?" & strQueryString
End If

Response.Write "Domain : " & strDomain & "</br>"
Response.Write "Path : " & strPath & "</br>"
Response.Write "QueryString : " & strQueryString & "</br>"
Response.Write "FullUrl : " & strFullUrl & "</br>"

Output:

Domain : www.google.com
Path : /gmail/inbox.asp
QueryString : uid=1421&skyid=2823595
FullUrl : https://www.google.com/gmail/inbox.asp?uid=1421&skyid=2823595
like image 32
Karthikeyan P Avatar answered Sep 29 '22 05:09

Karthikeyan P


Simple

Just use Request.ServerVariables("SCRIPT_NAME") and then do some string chopping to get the stuff you need.

like image 34
Chris Avatar answered Sep 29 '22 05:09

Chris


I think this would depend on the method you used to do the URL rewriting.

  1. Using IIS - Refer to this previous post on how to extract the full URL: get current url of the page (used URL Rewrite)

  2. Using 404 - This is how I've done it in the past and the only way to access the raw URL is to check the querystring. The 404 URL will look something like this:

    https://website.com/rewrite.asp?404;http://website.com/images/gal/boxes-pic004.asp
    

To get the URL, I use something like this:

    Function getURL()
        Dim sTemp
        sTemp = Request.Querystring
        ' the next line removes the HTTP status code that IIS sends, in the form "404;" or "403;" or whatever, depending on the captured error
        sTemp = Right(sTemp, len(sTemp) - 4)
        ' the next two lines remove both types of server names that IIS includes in the querystring
        sTemp = replace(sTemp, "http://" & Request.ServerVariables("HTTP_HOST") & ":80/", "")
        sTemp = replace(sTemp, "http://" & Request.ServerVariables("HTTP_HOST") & "/", "")
        sTemp = replace(sTemp, "https://" & Request.ServerVariables("HTTP_HOST") & "/", "")
        sTemp = replace(sTemp, "https://" & Request.ServerVariables("HTTP_HOST") & ":443/", "")
        ' the next bit of code will force our array to have at least 1 element
        getURL = sTemp
    End Function

This will get you the full raw URL, you can then extract the part you need by using simple split like:

    tmpArr = Split(getURL(),"/")
    strScriptName = tmpArr(UBound(tmpArr))

The strScriptName variable will then return "boxes-pic004.asp".

Hope this helps.

like image 36
Aki Avatar answered Sep 29 '22 07:09

Aki