Last active
November 27, 2023 13:02
-
-
Save RickStrahl/44e464b7bf6feb74c814c484ed9daa46 to your computer and use it in GitHub Desktop.
UrlEncoding on local Urls producing double encoded Uri.AbsoluteUri values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var part1 = new Uri("C:\\temp\\"); // double encodes when combining parts | |
var part2 = "assets/Image%20File.jpg"; | |
var uri = new Uri(part1, part2); | |
uri.Dump(); | |
uri.ToString().Dump(); // still encoded and shouldn't be | |
uri.AbsoluteUri.Dump(); // %2520 error | |
uri.LocalPath.Dump(); // still encoded and shouldn't be | |
part1 = new Uri("file:///C:\\temp\\"); // this works as expected | |
uri = new Uri(part1, part2); | |
uri.Dump(); | |
uri.ToString().Dump(); // raw but unencoded | |
uri.AbsoluteUri.Dump(); // raw and encoded | |
uri.LocalPath.Dump(); // unencoded as local file path | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment