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
편집을
var uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
string path = uri.GetLeftPart(UriPartial.Path);
또는
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);
을 (
Get url without querystring에서 발견)
또는
string url = "http://www.somesite.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye";
string path = url.Substring(0, url.IndexOf("?"));
돈 ' 이것이 URL 재 작성과 어떻게 관련되는지 보지 않으시겠습니까? Request.Url.AbsoluteUri? –
네,하지만 Request.Url.AbsoluteUri를 사용하면 http : //localhost/Default.aspx? pageid = 25가되어 URL 재 작성으로 인해 저에게 유용하지 않습니다. –