string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost/learnmore.aspx
string path = HttpContext.Current.Request.Url.AbsolutePath;
// /localhost/learnmore.aspx
string host = HttpContext.Current.Request.Url.Host;
// localhost
編輯:要刪除查詢字符串的項目:(從Get url without querystring找到)
var uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
string path = uri.GetLeftPart(UriPartial.Path);
OR
Uri url = new Uri("http://www.somesite.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");
string path = String.Format("{0}{1}{2}{3}", url.Scheme,
Uri.SchemeDelimiter, url.Authority, url.AbsolutePath);
或
string url = "http://www.somesite.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye";
string path = url.Substring(0, url.IndexOf("?"));
不要」 t看看這是如何與Url重寫相關的,你只需要一個完整的URL? Request.Url.AbsoluteUri? – 2012-04-20 09:49:19
是的,但如果我使用Request.Url.AbsoluteUri然後我得到http://localhost/Default.aspx?pageid = 25所以它對我沒有用,那是由於URL ReWritting – 2012-04-20 10:02:41