I'm working on a C# project where I need to combine a base URL with various endpoints. However, I'm running into issues when the endpoint has a leading slash. For example:
string baseUrl = "https://example.com/api/v1/"; string endpoint = "/sessions/logon/"; Uri baseUri = new Uri(baseUrl); Uri fullUri = new Uri(baseUri, endpoint); Console.WriteLine(fullUri); This code results in https://example.com/sessions/logon instead of the expected https://example.com/api/v1/sessions/logon. The leading slash in the endpoint causes it to override the base URL path.
Is there a robust way to combine URIs that correctly handles leading/trailing slashes?