我有一个这样的URL:
http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye
我想从中得到http://www.example.com/mypage.aspx。
你能告诉我怎么买吗?
我有一个这样的URL:
http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye
我想从中得到http://www.example.com/mypage.aspx。
你能告诉我怎么买吗?
当前回答
System.Uri。GetComponents,只是指定你想要的组件。
Uri uri = new Uri("http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");
uri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped);
输出:
http://www.example.com/mypage.aspx
其他回答
Silverlight的解决方案:
string path = HtmlPage.Document.DocumentUri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
简单的例子是使用子字符串:
string your_url = "http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye";
string path_you_want = your_url .Substring(0, your_url .IndexOf("?"));
var canonicallink = Request.Url.Scheme + "://" + Request.Url.Authority + Request.Url.AbsolutePath.ToString();
string url = "http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye";
string path = url.split('?')[0];
Request.RawUrl.Split('?')[0]
仅为url名!!