1. 程式人生 > 實用技巧 >Asp.Net獲取網站域名

Asp.Net獲取網站域名

Asp.Net獲取網站域名寫法

Request.Url.Scheme+“://”+Request.Url.Host
//結果就是http://www.xxx.com

獲取其他值說明

設當前頁完整地址是:http://www.xxx.net/aaa/bbb.aspx?id=5&name=kelli 
"http://"是協議名 
"www.xxx.net"是域名 
"aaa"是站點名 
"bbb.aspx"是頁面名(檔名) 
"id=5&name=kelli"是引數 
1】獲取 完整url (協議名+域名+站點名+檔名+引數) 程式碼如下: string url=Request.Url.ToString(); url
= http://www.xxx.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=Request.Url.Scheme; 
url= http

5】獲取 域名: 程式碼如下: string url=HttpContext.Current.Request.Url.Host; url= www.xxx.net 【6】獲取 引數: 程式碼如下: 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