asp.net獲取當前網址url的各種屬性(文件名、參數、域名 等)的代碼


設當前頁完整地址是: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:\temp\Default2.aspx 
Request.Url.LocalPath:------>/Default2.aspx 
Request.Url.AbsoluteUri:------>http://localhost:8080/Default2.aspx 
Request.Url.AbsolutePath:---------------------------->/Default2.aspx 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM