When writing a program, we often need to pass parameters on the page, such as page? Id = 1234, you can directly use string id = Request. QueryString ["id"]; on the page to obtain the value of the parameter id 1234. This is a basic knowledge that everyone knows.
The above method: Request. queryString, which analyzes the input URL and stores the result in a Collection of key values. We only need to set the key value, you can return the value corresponding to this key.
Assuming that this URL is not coming in through the Request, we can't get the URL parameter value through the Request, can we use a string url = "http://www.google.com/page? Id = 1234 "what about the Collection [key] = value? In addition, our URL parameters are URL encoded. This Encoding is usually Encoding. UTF8 or Encoding. getEncoding ("gb2312"), please note that the URL of Baidu uses gb2312, while Google uses UTF8. How can we determine whether to use gb2312 or UTF8 to decode the input string?
In the Baidu or Google search for related solutions, you will see this statement, that is, matching the URL through a regular expression, such as: Regex urlRegex = new Regex (@"(? : ^ |? | &) Courseid = (d *)(? : & | $) "); But I doubt the data integrity analyzed through this method. Is it possible to ensure that all data is matched? Later, I thought of simulating the Request Method in Microsoft. NET Framework to solve this problem. In fact, the above string id = Request. queryString ["id"]; can also be written as System. collections. specialized. nameValueCollection col = Request. queryString; string strID = col ["id"]; so let's construct this NameValueCollection!