Kentico CMS 7.0 Developer's Guide

Managing domain aliases

Managing domain aliases

Previous topic Next topic Mail us feedback on this topic!  

Managing domain aliases

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example adds a domain alias to a site.

 

private bool AddDomainAliasToSite()
{
    // Get the site object
    SiteInfo site = SiteInfoProvider.GetSiteInfo("MyNewSite");
 
    if (site != null)
    {
        // Create new site domain alias object
        SiteDomainAliasInfo newAlias = new SiteDomainAliasInfo();

 
        // Set the properties
        newAlias.SiteDomainAliasName = "127.0.0.1";
        newAlias.SiteID = CMSContext.CurrentSiteID;
 
        // Save the site domain alias
        SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(newAlias);
 
        return true;
    }
 
    return false;
}

 

The following example removes a domain alias from a site.

 

private bool DeleteSiteDomainAlias()
{
    // Get the site object
    SiteInfo si = SiteInfoProvider.GetSiteInfo("MyNewSite");
 
    if (si != null)
    {

      // Get the site domain alias
      SiteDomainAliasInfo deleteAlias = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo("127.0.0.1", si.SiteID);

 
        // Delete the site domain alias
        SiteDomainAliasInfoProvider.DeleteSiteDomainAliasInfo(deleteAlias);
 
        return (deleteAlias != null);
    }
 
    return false;
}