假設當前頁完整地址是:http://www.test.com:80/aaa/bbb.aspx?id=5&name=kelli
"http://"是協議名
"www.test.com"是域名
"80"是端口號
"aaa"是站點名
"bbb.aspx"是頁面名(文件名)
"id=5&name=kelli"是參數
【1】獲取 完整url (協議名+域名+站點名+文件名+參數)
string url=Request.Url.ToString();
url=http://www.test.com/aaa/bbb.aspx?id=5&name=kelli
【2】獲取 站點名+頁面名+參數:
string url=Request.RawUrl;
(或 string url=Request.Url.PathAndQuery;)
url=/aaa/bbb.aspx?id=5&name=kelli
【3】獲取 站點名+頁面名:
string url=HttpContext.Current.Request.Url.AbsolutePath;
(或 string url= HttpContext.Current.Request.Path;)
url=aaa/bbb.aspx
【4】獲取 域名:
string url=HttpContext.Current.Request.Url.Host;
url=www.test.com
【5】獲取 參數:
string url= HttpContext.Current.Request.Url.Query;
url=?id=5&name=kelli
【5】獲取 端口:
int port = HttpContext.Current.Request.Url.Port;
port = 80