---
title: Sites
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

## Sites

### Creating a new site

```csharp

// Creates a new site object
SiteInfo newSite = new SiteInfo();

// Sets the site properties
newSite.DisplayName = "New site";
newSite.SiteName = "NewSite";
newSite.Status = SiteStatusEnum.Stopped;
newSite.DomainName = "127.0.0.1";

// Saves the site to the database
SiteInfo.Provider.Set(newSite);

```

[> Back to list of examples](#toc)

### Updating a site

```csharp

// Gets the site
SiteInfo updateSite = SiteInfo.Provider.Get("NewSite");
if (updateSite != null)
{
    // Updates the site properties
    updateSite.DisplayName = updateSite.DisplayName.ToLower();

    // Saves the modified site to the database
    SiteInfo.Provider.Set(updateSite);
}

```

[> Back to list of examples](#toc)

### Updating multiple sites

```csharp

// Gets all sites whose code name starts with 'New'
var sites = SiteInfo.Provider.Get().WhereStartsWith("SiteName", "New");

// Loops through individual sites
foreach (SiteInfo site in sites)
{
    // Updates the site properties
    site.DisplayName = site.DisplayName.ToUpper();

    // Saves the modified site to the database
    SiteInfo.Provider.Set(site);
}

```

[> Back to list of examples](#toc)

### Assigning a culture to a site

```csharp

// Gets the site and culture objects
SiteInfo site = SiteInfo.Provider.Get("NewSite");
CultureInfo culture = CultureInfo.Provider.Get("ar-sa");

if ((site != null) && (culture != null))
{
    // Assigns the culture to the site
    CultureSiteInfo.Provider.Add(culture.CultureID, site.SiteID);
}

```

[> Back to list of examples](#toc)

### Removing a culture from a site

```csharp

// Gets the site and culture objects
SiteInfo site = SiteInfo.Provider.Get("NewSite");
CultureInfo culture = CultureInfo.Provider.Get("ar-sa");

if ((site != null) && (culture != null))
{
    // Removes the culture from the site
    CultureSiteInfo.Provider.Remove(culture.CultureID, site.SiteID);
}

```

[> Back to list of examples](#toc)

### Adding a domain alias to a site

```csharp

// Gets the site object
SiteInfo site = SiteInfo.Provider.Get("NewSite");

if (site != null)
{
    // Creates a new site domain alias object
    SiteDomainAliasInfo newAlias = new SiteDomainAliasInfo(SiteDomainAliasInfo.OBJECT_TYPE);                    
    newAlias.SiteDomainAliasName = "127.0.0.1";
    
    // Assigns the domain alias to the site
    newAlias.SiteID = site.SiteID;

    // Saves the site domain alias to the database
    SiteDomainAliasInfo.Provider.Set(newAlias);
}

```

[> Back to list of examples](#toc)

### Deleting a site's domain alias

```csharp

// Gets the site object
SiteInfo site = SiteInfo.Provider.Get("NewSite");

if (site != null)
{
    // Gets the specified domain alias for the site
    SiteDomainAliasInfo deleteAlias = SiteDomainAliasInfo.Provider.Get()
        .TopN(1)
        .WhereEquals("SiteDomainAliasName", "127.0.0.1")
        .WhereEquals("SiteID", site.SiteID)
        .FirstOrDefault();

    // Deletes the site domain alias
    SiteDomainAliasInfo.Provider.Delete(deleteAlias);
}

```

[> Back to list of examples](#toc)

### Deleting a site

```csharp

// Gets the site
SiteInfo deleteSite = SiteInfo.Provider.Get("NewSite");

if (deleteSite != null)
{
    // Deletes the site
    SiteInfo.Provider.Delete(deleteSite);
}

```

[> Back to list of examples](#toc)

## Site actions

### Starting a site

```csharp

// Gets the site
SiteInfo site = SiteInfo.Provider.Get("NewSite");
if (site != null)
{
    // Starts the site
    SiteInfoProvider.RunSite(site.SiteName);
}

```

[> Back to list of examples](#toc)

### Stopping a site

```csharp

// Gets the site
SiteInfo site = SiteInfo.Provider.Get("NewSite");
if (site != null)
{
    // Stops the site
    SiteInfoProvider.StopSite(site.SiteName);
}

```

[> Back to list of examples](#toc)
