I think the return value of the code you are running is depending on your siteUrl in episerver.config; have you tried making sure that your siteUrl is set to "https://:..."? If you want to return "https" when the request was "https" and "http" when the request was "http", I think you'll have to check the request object and make necessary changes to the resulting URL.
I believe the AbsoluteUrlBySettings will always use whatever you've written in your config file. You could always try using EPiServer's UrlBuilder on your link, and then getting the current scheme from the request object.
Something like:
var ub = new UrlBuilder(yourlink);
// or new UrlBuilder(EPiServer.Configuration.Settings.Instance.SiteUrl); and set the path property
ub.Scheme = HttpContext.Request.Url.Scheme;
ub.ToString();
Edit: too slow ^^;
Ah yes that'll work. I wanted a way to where I didn't have to do a string replace on the url. Thanks!
For certain caching scenarios it's smart to leave out the protocol, like for example widgets or other remote scripts usually does, <script src="//www.site.com/script.js" />. That way you can serve (and cache) the same markup for both http and https.
I agree but i'd rather have the protocol in the url than to do string replace
How can i get the absolute url to a page and have it change to https if im running that protocol?
At the moment im using this code: UriSupport.AbsoluteUrlBySettings(CurrentPage.GetExternalUrl()) which works well for getting the absolute url but it doesn't change to https if i run that protocol.
If it is obvious, the "GetExternalUrl" turns the LinkURL to a friendly url