Try our conversational search powered by Generative AI!

How to get absolute urls for https?

Vote:
 

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

#80144
Jan 15, 2014 16:42
Vote:
 

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

#80155
Jan 15, 2014 18:41
Vote:
 

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.

#80157
Jan 15, 2014 21:58
Vote:
 

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 ^^;

#80158
Edited, Jan 15, 2014 21:59
Vote:
 

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

#80173
Jan 16, 2014 8:50
Vote:
 

You're welcome :)

#80175
Jan 16, 2014 8:51
Vote:
 

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.

#80529
Jan 24, 2014 10:58
Vote:
 

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

#80538
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.