Get url parts without host
I have a url like this :
http://www.somesite.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye.
I want to get mypage.aspx?myvalue1=hello&myvalue2=goodbye from it开发者_开发问答 . Can you tell me how can I get it ?
Like this:
new Uri(someString).PathAndQuery
var uri = new Uri("http://www.somesite.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");
string pathOnly = uri.LocalPath; // "/mypage.aspx"
string queryOnly = uri.Query; // "?myvalue1=hello&myvalue2=goodbye"
string pathAndQuery = uri.PathAndQuery; // "/mypage.aspx?myvalue1=hello&myvalue2=goodbye"
Place your string URL into a URI object and then use the AbsolutePath & Query properties to get the URL parts you need.
Or use the PathAndQuery property to get both, which is what you need.
More information can be found here:
http://msdn.microsoft.com/en-us/library/system.uri_members%28v=VS.71%29.aspx
new Uri(System.AppDomain.CurrentDomain.BaseDirectory).Segments
精彩评论