Asp.net获取当前网址url的各种属性(文件名、参数、域名 等)

 在Asp.net里获取关于当前网址URL的各种属性


在这个Url中,

例如:当前网址为:http://www.shaneray.com/admin/Login.aspx?id=admin&pwd=admin

协议名是 "http://"
域名是 "www.shaneray.com"
站点名是 "admin"
页面名(文件名)是 "login.aspx"
参数是 "id=admin&pwd=admin"

一、获取完整的Url      即(协议名+域名+站点名+文件名+参数)

string url=Request.Url.ToString(); 
url= http://www.shaneray.com/admin/Login.aspx?id=admin&pwd=admin

二、获取站点名+页面名+参数

string url=Request.RawUrl; 
//或string url=Request.Url.PathAndQuery; 
url=/admin/Login.aspx?id=admin&pwd=admin

三、获取站点名+页面名

string url=HttpContext.Current.Request.Url.AbsolutePath; 
(或 string url= HttpContext.Current.Request.Path;) 
url= admin/Login.aspx

四、获取域名

string url=HttpContext.Current.Request.Url.Host; 
url= www.shaneray.com

五、获取参数

string url= HttpContext.Current.Request.Url.Query; 
url= ?id=admin&pwd=admin

十、其他属性

Request.RawUrl //获取客户端请求的URL信息(不包括主机和端口)------>/Login.aspx 
Request.ApplicationPath //获取服务器上ASP.NET应用程序的虚拟路径。------>/ 
Request.CurrentExecutionFilePath //获取当前请求的虚拟路径。------>/Login.aspx 
Request.Path //获取当前请求的虚拟路径。------>/Login.aspx 
Request.PathInfo //取具有URL扩展名的资源的附加路径信息------> 
Request.PhysicalPath //获取与请求的URL相对应的物理文件系统路径。------>E:\ShaneRay\Login.aspx 
Request.Url.LocalPath //------>/Login.aspx 
Request.Url.AbsoluteUri //------>http://www.shaneray.com/Login.aspx 
Request.Url.AbsolutePath //---------------------------->/Login.aspx 



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值