1. 程式人生 > >C#/Asp.Net 獲取各種Url的方法

C#/Asp.Net 獲取各種Url的方法

response cnblogs app 1=1 site col bsp quest path

比如有:http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QueryString2=2

Response.Write("<br/> " + HttpContext.Current.Request.Url.Host);
Response.Write("<br/> " + HttpContext.Current.Request.Url.Authority);
Response.Write("<br/> " + HttpContext.Current.Request.Url.Port);
Response.Write(
"<br/> " + HttpContext.Current.Request.Url.AbsolutePath); Response.Write("<br/> " + HttpContext.Current.Request.ApplicationPath); Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsoluteUri); Response.Write("<br/> " + HttpContext.Current.Request.Url.PathAndQuery);

結果:

localhost
localhost:60527
60527
/WebSite1test/Default2.aspx
/WebSite1test
http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QueryString1=2
/WebSite1test/Default2.aspx?QueryString1=1&QueryString2=2

C#/Asp.Net 獲取各種Url的方法