.NET C#獲取當前網頁地址信息

設當前頁完整地址是:http://www.jb51.net/aaa/bbb.aspx?id=5&name=kelli 
"http://"是協議名
"
www.jb51.net"是域名
"aaa"是站點名
"bbb.aspx"是頁面名(文件名)
"id=5&name=kelli"是參數
【1】獲取 完整url (協議名+域名+站點名+文件名+參數)

string url=Request.Url.ToString();
url=
 http://www.jb51.net/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.jb51.net

【5】獲取 參數:
string url= HttpContext.Current.Request.Url.Query;
url= ?id=5&name=kelli


Request.RawUrl:獲取客戶端請求的URL信息(不包括主機和端口)------>/Default2.aspx
Request.ApplicationPath:獲取服務器上ASP.NET應用程序的虛擬路徑。------>/
Request.CurrentExecutionFilePath:獲取當前請求的虛擬路徑。------>/Default2.aspx
Request.Path:獲取當前請求的虛擬路徑。------>/Default2.aspx
Request.PathInfo:取具有URL擴展名的資源的附加路徑信息------>
Request.PhysicalPath:獲取與請求的URL相對應的物理文件系統路徑。------>E:tempDefault2.aspx
Request.Url.LocalPath:------>/Default2

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章