I am generating a URI as follows (this code is simplified and falsified):
Uri baseUri = "http://localhost/MyApp/Account/Login";
Uri fullUri = GetFullUri(baseUri, user);
GetFullUri looks like this (this is in a .NET 2 assembly):
public Uri GetFullUri(Uri baseUri, User user)
{
string token = GetTokenFromUser(user); //Implementation not important.
//Create a new URI based on the base URI, adding a query string.
return new Uri(baseUri, string.Format("?Token={0}", token));
}
Calling GetFullUri from a .NET 4 assembly, the result is correct, fullUri looks like:
http://localhost/MyApp/Account/Login?Token=ABC123
Then I called the same exact code from a .NET 2 assembly and the result is incorrect, fullUri looks like:
http://localhost/MyApp/Account/?Token=ABC123
Notice how the .NET 2 result is missing the 4th and final segment, “Login”? What’s the deal with that?
Looks like a bug which was fixed in .NET 4.0. Try using the
UriBuilder, which works in both: