I\'m looking for canonical way of changing scheme of a given System.Uri instance with System.UriBuilder without crappy string manipulations and magic constants. Say I have>
Another iteration on Good Night Nerd Pride's answer, as an extension:
public static Uri RewriteHttps(this Uri originalUri)
{
return new UriBuilder(originalUri)
{
Scheme = Uri.UriSchemeHttps,
Port = originalUri.IsDefaultPort ? -1 : originalUri.Port // -1 => default port for scheme
}.Uri;
}