天天看点

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>

转载请注明:博客园

继续阅读