I have a redir page that takes some query parameters, notably a “page” parameter which, in turn, has its own query parameters. A simplified version might look like this.
http://www.example.com/redir.aspx?page=%5Bescaped address]&two=2
The following test fails because the System.Uri constructor is unescaping my inner page’s parameters. (kthx!)
Assert.AreEqual(
"http://www.ex.com/redir.aspx?page=inner.htm%3Fone%3D1%26two%3D2&three=3",
new Uri("http://www.ex.com/redir.aspx?page=inner.htm%3Fone%3D1%26two%3D2&three=3").ToString());
I’m actually getting http://www.ex.com/?page=inner.htm?one=1&two=2&three=3 which doesn’t even look like a decent URI to me, what with the 2 question marks and don’t really whose parameter that “three” is. As you can see from the test, inner.htm has 2 parameters, one and two, and three is for redir.
Am I all wet? Is this the right way to pass a URI to a URI?
No, the
Uriconstructor is doing the right thing. The test is failing because you’re callingUri.ToString(), which is broken by design.Don’t use
Uri.ToString(). UseUri.AbsoluteUriinstead.