编程语言
首页 > 编程语言> > C#/Asp.Net 获取各种Url的方法

C#/Asp.Net 获取各种Url的方法

作者:互联网

C#/Asp.Net 获取各种Url的方法

 

比如有: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
复制代码

标签:Current,Asp,Url,Request,Write,C#,HttpContext,Response
来源: https://www.cnblogs.com/Insist-Y/p/15820903.html