天天看點

Request擷取url資訊

在ASP.NET程式設計中經常需要用Request擷取url的有關資訊,Request中有多種方法擷取url資訊

連轉再載再測如下: 

(一)頁面Test.aspx

protected void Page_Load(object sender, EventArgs e)

{

    Response.Write("Request.ApplicationPath:" + Request.ApplicationPath + "<br/>");

    Response.Write("Request.CurrentExecutionFilePath:" + Request.CurrentExecutionFilePath + "<br/>");

    Response.Write("Request.Path:" + Request.Path + "<br/>");

    Response.Write("Request.PathInfo:" + Request.PathInfo + "<br/>");

    Response.Write("Request.PhysicalApplicationPath:" + Request.PhysicalApplicationPath + "<br/>");

    Response.Write("Request.PhysicalPath:" + Request.PhysicalPath + "<br/>");

    Response.Write("Request.RawUrl:" + Request.RawUrl + "<br/>");

    Response.Write("Request.Url.AbsolutePath:" + Request.Url.AbsolutePath + "<br/>");

    Response.Write("Request.Url.AbsoluteUri:" + Request.Url.AbsoluteUri + "<br/>");

    Response.Write("Request.Url.Host:" + Request.Url.Host + "<br/>");

Response.Write("Request.Url.LocalPath:" + Request.Url.LocalPath + "<br/>");

if (Request.UrlReferrer != null)

            Response.Write("上一頁的位址:" + Request.UrlReferrer.AbsolutePath);

//UrlReferrer:擷取有關用戶端上次請求的 URL 的資訊,該請求連結到目前的 URL。

}

(二)頁面a.aspx

在頁面a.aspx中添加對Test.aspx的連結

<a href="Test.aspx" target="_self">點選</a>

(三)通路a.aspx,并點選連結

結果:

Request.ApplicationPath:/web2

Request.CurrentExecutionFilePath:/web2/Test.aspx

Request.Path:/web2/Test.aspx

Request.PathInfo:

Request.PhysicalApplicationPath:E:\test8\Net35\web2\

Request.PhysicalPath:E:\test8\Net35\web2\Test.aspx

Request.RawUrl:/web2/Test.aspx

Request.Url.AbsolutePath:/web2/Test.aspx

Request.Url.AbsoluteUri:http://localhost:20372/web2/Test.aspx

Request.Url.Host:localhost

Request.Url.LocalPath:/web2/Test.aspx

上一頁的位址:/web2/la1.aspx

iframe裡測了一下,沒有變化

部落格園大道至簡

<a href="http://www.cnblogs.com/jams742003/" target="_blank">http://www.cnblogs.com/jams742003/</a>

轉載請注明:部落格園

繼續閱讀