ASP.NET获取URL及虚拟根目录

获取当前域名
Request.Url.Host

在ASP.NET中可以对Reqeust对象中获取web应用程序或网站的虚拟根目录,物理文件路径等信息,可以解析出URI的相关目录.

1:测试代码

测试URL :http://localhost:8080/Default2.aspx

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

2:测试结果

Request.RawUrl: 获取客户端请求的 URL 信息(不包括主机和端口)------> /Default2.aspx
Request.ApplicationPath :获取服务器上 ASP.NET 应用程序的虚拟路径。------> /
Request.CurrentExecutionFilePath : 获取当前请求的虚拟路径。 ------> /Default2.aspx
Request.Path : 获取当前请求的虚拟路径。 ------> /Default2.aspx
Request.PathInfo : 取具有 URL 扩展名的资源的附加路径信息 ------>
Request.PhysicalPath: 获取与请求的 URL 相对应的物理文件系统路径。 ------>E:\temp\Default2.aspx
Request.Url.LocalPath : ------>/Default2.aspx
Request.Url.AbsoluteUri: ------>http://localhost:8080/Default2.aspx
Request.Url.AbsolutePath : ---------------------- ------>/Default2.aspx
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值