ASP Get URL Function Summary _ Application Tips

Source: Internet
Author: User
method One: Simple, no parameters, only one virtual path
Copy Code code as follows:

GetUrl =request ("url")

For example: HTTP://127.0.0.1/SHIYAN.ASP?DFSDFSF=DSFSDFD&AA=DDDD
Get as: shiyan.asp
Copy Code code as follows:

<%
Dim Changdu,url,ends,wurl
Changdu=len (Request. ServerVariables ("URL"))
Url=instrrev (Request. ServerVariables ("URL"), "/"
Url=url+1
Ends=changdu+1-url
Wurl=mid (Request. ServerVariables ("URL"), Url,ends)
%>

method Two: Get the whole URL, get the parameter
Copy Code code as follows:

' Get the address of the current page
Function GetUrl ()
On Error Resume Next
Dim strtemp
If LCase (Request.ServerVariables ("HTTPS") = "Off" Then
strtemp = "http://"
Else
strtemp = "https://"
End If
strtemp = strtemp & Request.ServerVariables ("SERVER_NAME")
If Request.ServerVariables ("Server_port") <> Then strtemp = strtemp & ":" & Request.ServerVariables ("SER Ver_port ")
strtemp = strtemp & Request.ServerVariables ("URL")
If Trim (request.querystring) <> "" Then strtemp = strtemp & "?" & Trim (Request.QueryString)
GETURL = strtemp
End Function

For example: HTTP://127.0.0.1/SHIYAN.ASP?DFSDFSF=DSFSDFD&AMP;AA=DDDD
Get as: http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd

method Three: Get the virtual path, get the parameter
Copy code code as follows:

Private Function GetUrl ()
Dim Scriptaddress,m_itemurl,m_item
scriptaddress = CStr (Request.ServerVariables ("Script_name")) ' Get current address
M_itemurl = ""
If (Request.QueryString <> "") Then
scriptaddress = scriptaddress & "?"
For each m_item in Request.QueryString
If M_item = "Page_num" Then Exit for ' The function here is to filter out the parameters of this page of Page_num (this parameter is set by itself in the page_turn.asp, depending on the individual settings), otherwise each page will overlay this parameter, Although it does not affect the function, but it is not very good
If InStr (page,m_item) =0 Then
M_itemurl = M_itemurl & m_item & "=" & Server.URLEncode (Request.QueryString ("" &M_Item& ""))
Else
M_itemurl = M_itemurl & m_item & "=" & Server.URLEncode (Request.QueryString ("" &M_Item& ")) &" & "
End If
Next
Else
scriptaddress = scriptaddress & "?"
End If
GETURL = scriptaddress & M_itemurl
End Function

For example: HTTP://127.0.0.1/SHIYAN.ASP?DFSDFSF=DSFSDFD&AMP;AA=DDDD
Get as:/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd

method Four: Get only the parameter part string
Copy Code code as follows:

Function GetUrl ()
On Error Resume Next
Dim strtemp
If LCase (Request.ServerVariables ("HTTPS") = "Off" Then
strtemp = "http://"
Else
strtemp = "https://"
End If
strtemp = strtemp & Request.ServerVariables ("SERVER_NAME")
If Request.ServerVariables ("Server_port") <> Then strtemp = strtemp & ":" & Request.ServerVariables ("SER Ver_port ")
strtemp = strtemp & Request.ServerVariables ("URL")
If Trim (request.querystring) <> "" Then strtemp = strtemp & "?" & Trim (Request.QueryString)
GETURL = strtemp
Geturl=mid (Geturl,instr (Geturl, "?") +1)
End Function

For example: HTTP://127.0.0.1/SHIYAN.ASP?DFSDFSF=DSFSDFD&AMP;AA=DDDD
Get as: dfsdfsf=dsfsdfd&aa=dddd

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.