How to get absolute urls for https?


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

Jan 15, 2014 16:42

Sorry, made a typo. It's suppose to be "if it isn't obvious"

Jan 15, 2014 18:41

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.

Jan 15, 2014 21:58

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;



 Edit: too slow ^^;

Edited, Jan 15, 2014 21:59

Ah yes that'll work. I wanted a way to where I didn't have to do a string replace on the url. Thanks!

Jan 16, 2014 8:50

You're welcome :)

Jan 16, 2014 8:51

For certain caching scenarios it's smart to leave out the protocol, like for example widgets or other remote scripts usually does, <script src="//" />. That way you can serve (and cache) the same markup for both http and https.

Jan 24, 2014 10:58

I agree but i'd rather have the protocol in the url than to do string replace

Jan 24, 2014 12:35
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.