ASP.NET擷取URL方法匯總_實用技巧

來源:互聯網
上載者:User

//擷取完整url (協議名+網域名稱+網站名+檔案名稱+參數)

string fullUrl = Request.Url.ToString();

//擷取用戶端請求的URL資訊(不包括主機和連接埠)

string rawUrl = Request.RawUrl;

//擷取網站名+頁面名

string absolutePath = Request.Url.AbsolutePath;

//擷取主機部分

string urlHost = Request.Url.Host;

//擷取參數部分

string urlQuery = Request.Url.Query;

//擷取伺服器上ASP.NET應用程式的虛擬路徑

string ApplicationPath = Request.ApplicationPath;

//擷取當前請求的虛擬路徑

string CurrentExecutionFilePath = Request.CurrentExecutionFilePath;

//擷取當前請求的虛擬路徑

string Path = Request.Path;

//擷取具有URL副檔名的資源的附加路徑資訊

string PathInfo = Request.PathInfo;

//擷取與請求的URL相對應的物理檔案系統路徑

string PhysicalPath = Request.PhysicalPath;

//擷取檔案名稱的本地作業系統表示形式

string LocalPath = Request.Url.LocalPath;

//擷取絕對URL

string AbsoluteUri = Request.Url.AbsoluteUri;

完整代碼示範

複製代碼 代碼如下:

StringBuilder sb = new StringBuilder();
sb.Append("擷取完整url(協議名+網域名稱+網站名+檔案名稱+參數):" + fullUrl + "<br />");
sb.Append("擷取用戶端請求的URL資訊(不包括主機和連接埠):" + rawUrl + "<br />");
sb.Append("擷取網站名+頁面名:" + absolutePath + "<br />");
sb.Append("擷取主機部分:" + urlHost + "<br />");
sb.Append("擷取參數部分:" + urlQuery + "<br />");
sb.Append("擷取應用程式的虛擬應用程式根路徑:" + ApplicationPath + "<br />");
sb.Append("擷取當前請求的虛擬路徑:" + Path + "<br />");
sb.Append("擷取具有URL副檔名的資源的附加路徑資訊:" + PathInfo + "<br />");
sb.Append("擷取與請求的URL相對應的物理檔案系統路徑:" + PhysicalPath + "<br />");
sb.Append("擷取檔案名稱的本地作業系統表示形式:" + LocalPath + "<br />");
sb.Append("擷取絕對URL:" + AbsoluteUri + "<br />");
Response.Write(sb.ToString());

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.