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 virtual directory 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 + virtual directory name + file name + parameter)
String url = Request. Url. ToString ();
Url = http://www.test.com/aaa/bbb.aspx? Id = 5 & name = kelli
[2] obtain the virtual directory name + Page name + parameter:
String url = Request. RawUrl;
(Or string url = Request. Url. PathAndQuery ;)
Url =/aaa/bbb. aspx? Id = 5 & name = kelli
[3] obtain the virtual directory 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
(This is indeed valid. Thanks to the original author .)
Request. QueryString ["id"] and Request. QueryString ["name"] Access Parameters
Request. UrlReferrer can obtain the url Information of the client's last Request, so that we can return the "Previous Page" through this attribute ".
Similarly, Request. UrlReferrer. Query can obtain the relevant parameters of the client's last Request url.