Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to get list of website?

Vote:
 

Hi,

Can anyone tell me how to get list of websites that are configured in Admin/Config/Manage Websites?

Thank in advance,

Linh

#139373
Oct 01, 2015 6:56
Vote:
 

Hi,

There is SiteDefinitionRepository that you could resolve in ServiceLocator:

var siteDefinitionRepository = ServiceLocator.Current.GetInstance<SiteDefinitionRepository>();
var siteDefinitions = siteDefinitionRepository.List().ToList();
foreach (var siteDefinition in siteDefinitions)
{
    var siteURl = siteDefinition.SiteUrl;
    foreach (var hostDefinition in siteDefinition.Hosts)
    {
        var uri = hostDefinition.Name;
    }
}
#139374
Oct 01, 2015 8:19
Vote:
 

Hi,

I think, that you can get hosts wihtout SiteDefinitionRepository.

You should use class SiteDefinition from namespace EPiServer.Web.

For exmaple:

EPiServer.Web.SiteDefinition.Current.Hosts

results:

Count = 7
    [0]: localhost, sv
    [1]: localhost:1111, sv
    [2]: *
    [3]: www.myproject.pl, pl
    [4]: www.myproject.no, no
    [5]: www.myproject.se, sv
    [6]: www.myproject.com

Best Regards

#139395
Oct 01, 2015 12:50
Vote:
 

Hi,

Thank you all. That's exactly what I need.

Thank again

#139441
Oct 02, 2015 10:13
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.