Analysis and summarization of several methods for ASP to obtain URL parameters

Source: Internet
Author: User
Tags servervariables

We need to use this function. How can we test it? Code
Assume that the address is:
Http://dxy.com: 8082/test/geturl. asp? Param-VR52tmx3syn03777.html

Method 1: simple. There is no parameter, and there is only one virtual path.Copy codeThe Code is as follows: geturl = request ("url") ', because we do not have the url = character, we can directly pass it.

Method 2: Obtain the entire URL and obtain the parameters.Copy codeThe Code is 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") <> 80 then strtemp = strtemp & ":" & request. servervariables ("server_port ")
Strtemp = strtemp & request. servervariables ("url ")
If trim (request. querystring) <> "then strtemp = strtemp &"? "& Trim (request. querystring)
Geturl = strtemp
End Function

The Path obtained by testing this code is:
/Test/geturl. asp? Param-VR52tmx3syn03777.html =

Method 2: Obtain the virtual path and obtain the parameters.

Copy code The Code is as follows: Private function geturl ()
Dim scriptaddress, m_itemurl, m_item
Scriptaddress = CSTR (request. servervariables ("script_name") 'gets the 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 'Here, the function is to filter out the page_num page parameters (this parameter is set in page_turn.asp and changed according to personal settings ), otherwise, this parameter will be superimposed on every page turning. Although this parameter does not affect the function, it is always not 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 address obtained from the above Code is
Http://dxy.com: 8082/test/geturl. asp? Param-VR52tmx3syn03777.html

Basically

If you just want to get? We can use the following codeCopy codeThe Code is as follows: Response. Write Replace (request. querystring, ". html ","")

What we get is that the Param-VR52tmx3syn03777 meets our needs.

PS: all the above cases are for pure ASP. If combined with urlrewrite, the functions will be enhanced, and the search will be more friendly.

Related Article

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.