2011-01-06 10 views

Antwort

28

So:

new Uri(someString).PathAndQuery 
+3

Um die Namespace "URL" Klasse gehört? Bist du sicher, dass es Url ist und nicht Uri? – HABJAN

+1

@HABJAN: Du hast recht; mein Fehler. – SLaks

21
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"