UriSupport.AbsoluteUrlBySettings

Vote:
 

Hi,

My test site and localhost share the same database.

Under Admin / Manage Websites / Hostnames, I've added the following values:

  • *
  • localhots:12345
  • mydomain.com

When running the website from localhost, UriSupport.SiteUrl returns http://mydomain.com instead of http://localhost:12345

I'm trying to convert an internal URL to an absolute external URL using this code snippet:

Global.UrlRewriteProvider.ConvertToExternal(urlBuilder, null, Encoding.UTF8);
var friendlyUrl = UriSupport.AbsoluteUrlBySettings(urlBuilder.ToString());

Any help would be greatly appreciated.

#116948
Feb 08, 2015 17:15
Vote:
 

Hi.

Hostnames are probably not checked in that method. What you need to change is the site URL (the box above the hostnames).

I've never used UriSupport.SiteURL, but I guess that a shorthand to SiteDefinition.Current.SiteURL, http://world.episerver.com/Documentation/Class-library/?documentId=cms/7.5/A3A2683.

#116949
Feb 08, 2015 18:45
Vote:
 

Thanks for your help!

I cannot modify the site URL because EPiServer database is shared between localhost and mydomain.com, and mydomain.com is more important than localhost.

I could solve this in 2 ways:

  • Use the relative URLs instead of absolute URLs
  • Get Request.Url.GetLeftPart(UriPartial.Authority) and append urlBuilder.ToString()

I was hoping that this can be solved by some EPiServer function which takes hostnames and HttpContext.Current into account :)

#116950
Feb 08, 2015 20:24
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.