I am trying to create a uri, but for some reason is the path being decoded everytime, causing problems with my browser trying to access the page the uri build?
POC:
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
var newLocation = new UriBuilder()
{
Scheme = Uri.UriSchemeHttps,
Host = "localhost",
Path = "/WebResource.axd?d=0"
}.Uri;
Console.WriteLine($"Hello World {newLocation}");
}
}
This outputs:
Hello World
Hello World https://localhost/WebResource.axd?d=0
I would have expected:
Hello World
Hello World https://localhost/WebResource.axd?d=0
CodePudding user response:
Perhaps it is converting the question mark because you specified the question mark in the .path
instead of in the .query
. Try moving the ?d=0
into the .query
and see if you get the same results.
Or, try loading the full URL into the UriBuilder
using this overload like in the MS documentation: UriBuilder baseUri = new UriBuilder("http://www.contoso.com/default.aspx?Param1=7890");
CodePudding user response:
I’m no expert, but it looks like it’s trying to replace the question mark, with it’s ASCII code, or 3F(?). This is probably because the question mark means a query in the browser, and is not considered part of the URI. Just a guess, I don’t know how I would fix it.
Hope I could help!