您的位置:首页 > 编程语言 > ASP

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

2013-08-20 11:06 260 查看
获取当前域名

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ASP.NET URL Request