request获取url的方法总结

 辣么多属性、方法  不用就忘了  ,当需要用的时候挠头也想不到,现在总结一下 以备用

例如:http://localhost/testweb/default.aspx

1.Request.ApplicationPath;  获取服务器上ASP.NET应用程序的虚拟应用程序根路径

2.Request.AppRelativeCurrentExecutionFilePath;  获取应用程序根的虚拟路径,使用~使成为相对路径
3. Request.CurrentExecutionFilePath;  获取当前请求的虚拟路径
4.Request.FilePath;    获取当前请求的虚拟路径
5.Request.MapPath("virtualpath"); 将指定虚拟路径映射到物理路径
6.Request.Path;   获取当前请求的虚拟路径
7.Request.PathInfo; 获取具有url扩展名的资源的附加路径信息
8.Request.PhysicalApplicationPath; 获取当前正在执行的服务器应用程序的根目录的物理文件系统路径
9.Request.PhysicalPath; 获取与请求的url相对应的物理文件系统路径
10.Request.RawUrl;获取当前请求的原始url
11.Request.Url  获取当前请求的url

Request.Url.AbsolutePath: /testweb/default.aspx
Request.Url.AbsoluteUri: http://www.test.com/testweb/default.aspx
Request.Url.Host: www.test.com
Request.Url.LocalPath: /testweb/default.aspx

12.Request.UrlReferrer 获取客户端上次请求的url信息,该请求连接到当前url

--ServerVariables :获取web服务器变量的集合

                  foreach (string r in Request.ServerVariables)
                  {
                      Response.Write(r + ">>>" + Request.ServerVariables[r] + "<hr>");
                  }

原文地址:https://www.cnblogs.com/yuanyanyan/p/5473816.html