在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