asp.net獲取當前頁面文件名,參數,域名等方法


ASP.net后台獲取當前頁面的文件名

System.IO.Path.GetFileName(Request.Path).ToString();

獲取當前頁面文件名,參數,域名等方法

假設當前頁完整地址是:http://www.test.com/aaa/bbb.aspx?id=5&name=kelli

"http://"是協議名

"www.test.com"是域名

"aaa"是虛擬目錄名

"bbb.aspx"是頁面名(文件名)

"id=5&name=kelli"是參數


【1】獲取 完整url (協議名+域名+虛擬目錄名+文件名+參數)

string url=Request.Url.ToString();

url= http://www.test.com/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.test.com

【5】獲取 參數:

string url= HttpContext.Current.Request.Url.Query;

url= ?id=5&name=kelli

Request.QueryString["id"]和Request.QueryString["name"]訪問各參數

Request.UrlReferrer可以獲取客戶端上次請求的url的有關信息, 這樣我們就可以通過這個屬性返回到“上一頁”。

同樣地,Request.UrlReferrer.Query可以獲取客戶端上次請求的url的有關參數部分。


Request.ApplicationPath:    /testweb  
   Request.CurrentExecutionFilePath:    /testweb/default.aspx  
   Request.FilePath:    /testweb/default.aspx  
   Request.Path:    /testweb/default.aspx  
   Request.PathInfo:   
   Request.PhysicalApplicationPath:    E:\WWW\testweb\  
   Request.PhysicalPath:    E:\WWW\testweb\default.aspx  
   Request.RawUrl:    /testweb/default.aspx  
   Request.Url.AbsolutePath:    /testweb/default.aspx  
   Request.Url.AbsoluteUri:    http://www.test.com/testweb/default.aspx  
   Request.Url.Host:    www.test.com  
   Request.Url.LocalPath:    /testweb/default.aspx


免責聲明!

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



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