Rocky Singh
Rocky Singh

Reputation: 15440

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 ?

Upvotes: 36

Views: 32145

Answers (4)

RJ Thompson
RJ Thompson

Reputation: 136

new Uri(System.AppDomain.CurrentDomain.BaseDirectory).Segments

Upvotes: 0

HABJAN
HABJAN

Reputation: 9338

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"

Upvotes: 46

SLaks
SLaks

Reputation: 887857

Like this:

new Uri(someString).PathAndQuery

Upvotes: 59

MrEyes
MrEyes

Reputation: 13750

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

Upvotes: 0

Related Questions