The very simplest way to do this is:

 if (IsHttps())
{
    url = url.Replace("http://", "https://");
}


public static bool IsHttps()
        {
            return HttpContext.Current.Request.IsSecureConnection;
        }


Enjoy !

(This change is currently live on my website)