[C#][頁面]獲取當前頁面的url信息

測試url : http://www.test.com:80/aaa/a.aspx?id=5&name=yh

【1】獲取 完整url (協議名+域名+站點名+文件名+參數)
string url=Request.Url.ToString();

【2】獲取 域名:
string url=HttpContext.Current.Request.Url.Host;

【3】獲取 端口:
int port = HttpContext.Current.Request.Url.Port;

【4】獲取 文件路徑+頁面名:
string url= HttpContext.Current.Request.Path;

【5】獲取 文件路徑+頁面名+參數:
string url=Request.RawUrl;

【6】獲取 參數(?號及其後面的參數):
string url= HttpContext.Current.Request.Url.Query;

 

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