2011-01-06 12 views

risposta

28

Ti piace questa:

new Uri(someString).PathAndQuery 
+3

A cui namespace "URL" classe appartiene? Sei sicuro che sia Url e non Uri? – HABJAN

+1

@HABJAN: hai ragione; errore mio. – 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" 
Problemi correlati