陈斌彬的技术博客

Stay foolish,stay hungry

C# Request 获取完整 URL

假设当前页完整地址是:http://blog.csdn.net/hashxu/article.aspx?Action=Get&PostId=6858577

1.获取完整url

string url=Request.Url.ToString();

url= http://blog.csdn.net/hashxu/article.aspx?Action=Get&PostId=6858577

2.获取 ID+页面名+参数:

string url=Request.RawUrl;

(或 string url=Request.Url.PathAndQuery;)

url= /hashxu/article.aspx?Action=Get&PostId=6858577

3.获取 ID+页面名:

string url=HttpContext.Current.Request.Url.AbsolutePath;

(或 string url= HttpContext.Current.Request.Path;)

url= hashxu/article.aspx

4.获取域名:

string url=HttpContext.Current.Request.Url.Host;

url= blog.csdn.net

5.获取参数:

string url= HttpContext.Current.Request.Url.Query;

url= ?Action=Get&PostId=6858577