ASP.NET获取URL方法汇总 //获取完整url (协议名+域名+站点名+文件名+参数) string fullUrl = Request.Url.ToString(); //获取客户端请求的URL信息(不包括主机和端口) string rawUrl = Request.RawUrl; //获取站点名+页面名 string absolutePath = Request.Url.AbsolutePath; //获取主机部分 string urlHost = Request.Url.Host; //获取参数部分 string urlQuery = Request.Url.Query; //获取服务器上ASP.NET应用程序的虚拟路径 string ApplicationPath = Request.ApplicationPath; //获取当前请求的虚拟路径 string CurrentExecutionFilePath = Request.CurrentExecutionFilePath; //获取当前请求的虚拟路径 string Path = Request.Path; //获取具有URL扩展名的资源的附加路径信息 string PathInfo = Request.PathInfo; //获取与请求的URL相对应的物理文件系统路径 string PhysicalPath = Request.PhysicalPath; //获取文件名的本地操作系统表示形式 string LocalPath = Request.Url.LocalPath; //获取绝对URL string AbsoluteUri = Request.Url.AbsoluteUri; 完整代码演示 复制代码 代码如下: StringBuilder sb = new StringBuilder(); sb.Append("获取完整url(协议名+域名+站点名+文件名+参数):" + fullUrl + "
"); sb.Append("获取客户端请求的URL信息(不包括主机和端口):" + rawUrl + "
"); sb.Append("获取站点名+页面名:" + absolutePath + "
"); sb.Append("获取主机部分:" + urlHost + "
"); sb.Append("获取参数部分:" + urlQuery + "
"); sb.Append("获取应用程序的虚拟应用程序根路径:" + ApplicationPath + "
"); sb.Append("获取当前请求的虚拟路径:" + Path + "
"); sb.Append("获取具有URL扩展名的资源的附加路径信息:" + PathInfo + "
"); sb.Append("获取与请求的URL相对应的物理文件系统路径:" + PhysicalPath + "
"); sb.Append("获取文件名的本地操作系统表示形式:" + LocalPath + "
"); sb.Append("获取绝对URL:" + AbsoluteUri + "
"); Response.Write(sb.ToString());