C # obtain URL parameters,
Suppose the full address of the current page is: http://www.test.com/aaa/bbb.aspx? Id = 5 & name = kelli
"Http: //" is the protocol name.
"Www.test.com" is a domain name
"Aaa" is the site name
"Bbb. aspx" is the page name (file name)
"Id = 5 & name = kelli" is a parameter
[1] obtain the complete url (protocol name + domain name + site name + file name + parameter)
String url = Request. Url. ToString ();
Url = http://www.test.com/aaa/bbb.aspx? Id = 5 & name = kelli
[2] retrieve site name + Page name + parameters:
String url = Request. RawUrl;
(Or string url = Request. Url. PathAndQuery ;)
Url =/aaa/bbb. aspx? Id = 5 & name = kelli
[3] retrieve site name + Page name:
String url = HttpContext. Current. Request. Url. AbsolutePath;
(Or string url = HttpContext. Current. Request. Path ;)
Url = aaa/bbb. aspx
[4] retrieve domain names:
String url = HttpContext. Current. Request. Url. Host;
Url = www.test.com
[5] GET parameters:
String url = HttpContext. Current. Request. Url. Query;
Url =? Id = 5 & name = kelli
Reprinted from: http://www.aspnetjia.com