asp.net获取当前请求的url
设当前页完整地址是:http://www.dgshop.com/Home/Manager?id=2¶=ASFDG
【1】获取 完整url
代码如下:
string url=Request.Url.ToString();
url= http://www.dgshop.com/Home/Manager?id=2¶=ASFDG
url= http://www.dgshop.com/Home/Manager?id=2¶=ASFDG
【2】获取 站点名+页面名+参数:
代码如下:
string url=Request.RawUrl;
(或 string url=Request.Url.PathAndQuery;)
url=/Home/Manager?id=2¶=ASFDG
(或 string url=Request.Url.PathAndQuery;)
url=/Home/Manager?id=2¶=ASFDG
【3】获取 站点名+页面名:
代码如下:
string url=HttpContext.Current.Request.Url.AbsolutePath;
(或 string url= HttpContext.Current.Request.Path;)
url= Home/Manager
(或 string url= HttpContext.Current.Request.Path;)
url= Home/Manager
【4】获取 域名:
代码如下:
string url=HttpContext.Current.Request.Url.Host;
url= www.dgshop.com
url= www.dgshop.com
【5】获取 参数:
代码如下:
string url= HttpContext.Current.Request.Url.Query;
url= ?id=2¶=ASFDG
url= ?id=2¶=ASFDG