Analysis and summary of several methods for obtaining URL parameters from ASP [Original]_ application techniques

Source: Internet
Author: User
Need to use this function, not how to test it, after the test to give specific code
If the address is:
Http://dxy.com:8082/test/geturl.asp?Param-VR52tmx3syn03777.html

Method One: Simple, no parameters, only one virtual path
Copy Code code as follows:

GetUrl =request ("url") ' This is because we have no url= what the word is, so just pass it off.

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

The path tested by this code is:
/test/geturl.asp? Param-vr52tmx3syn03777.html=

Method Two: Obtains the virtual path, obtains 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

The above code gets the address
Http://dxy.com:8082/test/geturl.asp?Param-VR52tmx3syn03777.html

Basically, almost.

If just to get the thing behind the number, we can use the following code
Copy Code code as follows:

Response.Write Replace (Request.QueryString, ". html", "")

The only thing we get is param-vr52tmx3syn03777, does it satisfy our needs?

PS: All the above situation is only for pure ASP, if combined with urlrewrite, the function will be enhanced, search friendly type, will also strengthen

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.