Chani Poz
Chani Poz

Reputation: 1463

Create absolute Uri in c#

My code does not work, why?

Uri urlNext = new Uri("product/100.aspx",UriKind.RelativeOrAbsolute);
urlNext = new Uri(new Uri("http://www.camb.com/used"), urlNext);
string url = urlNext.AbsoluteUri;

I want to get: "http://www.camb.com/used/product/100.aspx"
Instead I get: "http://www.camb.com/product/100.aspx"

Upvotes: 1

Views: 4797

Answers (1)

ígor
ígor

Reputation: 1164

You need / at end of uri:

Uri urlNext = new Uri("product/100.aspx",UriKind.RelativeOrAbsolute);
urlNext = new Uri(new Uri("http://www.camb.com/used/"), urlNext);
string url = urlNext.AbsoluteUri;

Upvotes: 10

Related Questions