Classic ASP - get full url name

2019-04-07 17:20发布

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

标签: asp-classic
4条回答
干净又极端
2楼-- · 2019-04-07 18:03

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.

查看更多
一夜七次
3楼-- · 2019-04-07 18:19
<%
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.

查看更多
混吃等死
4楼-- · 2019-04-07 18:19

Simple

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

查看更多
Lonely孤独者°
5楼-- · 2019-04-07 18:20

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
查看更多
登录 后发表回答