---
title: Excluding content from staging and integration
related:
  - https://docs.kentico.com/13/deploying-websites/content-staging.md
  - https://docs.kentico.com/13/integrating-3rd-party-systems/using-the-integration-bus.md
  - https://docs.kentico.com/13/custom-development/handling-global-events.md
  - https://docs.kentico.com/13/custom-development/handling-global-events/reference-global-system-events.md
---

> 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).

[Event handlers](https://docs.kentico.com/13/custom-development/handling-global-events.md) allow you to disable [content staging](https://docs.kentico.com/13/deploying-websites/content-staging.md) and [integration bus synchronization](https://docs.kentico.com/13/integrating-3rd-party-systems/using-the-integration-bus.md) for certain pages or objects. The system provides two types of events that you can use:

- [Handling the changes of pages or objects](#excluding-content-by-handling-page-or-object-changes)
- [Handling the creation of staging or integration tasks](#excluding-content-by-handling-synchronization-tasks)

## Excluding content by handling page or object changes

When changes are made to pages and objects (such as creating, editing or deleting), the system logs the change data. [Content staging](https://docs.kentico.com/13/deploying-websites/content-staging.md) and the [integration bus](https://docs.kentico.com/13/integrating-3rd-party-systems/using-the-integration-bus.md) use the data to create synchronization tasks, which then transfer the changes to the target server or application.

To completely prevent the system from starting the staging or integration process, handle the following events:

- **DocumentEvents.LogChange.Before**
- **ObjectEvents.LogChange.Before** (or **Info.TYPEINFO.Events** for specific object types)

You can use two different approaches to disable staging or integration inside the event handlers:

> **Info:** Set the properties of the event handler's **LogDocumentChangeArgs/LogObjectChangeArgs** parameter:
>
> ```csharp
>
> e.Settings.LogStaging = false;
> e.Settings.LogIntegration = false;
>
> ```
>
> Directly switches off logging of staging or integration tasks. The properties can be changed later during the execution of the _LogChange_ event.

**OR**

> **Info:** Call the **Using** method of the event handler's **LogDocumentChangeArgs/LogObjectChangeArgs** parameter with a new **CMSActionContext** object as the parameter. Set the **LogSynchronization** or **LogIntegration** properties in the _CMSActionContext_ constructor.
>
> ```csharp
>
> e.Using(new CMSActionContext() {LogSynchronization = false, LogIntegration = false} );
>
> ```
>
> Disables logging of staging or integration tasks within the entire context of the _LogChange_ event.

### Example

The following example demonstrates how to use **LogChange** handlers to disable content staging and integration for pages in the _/Archive_ section of a website.

1. Open your Xperience solution in Visual Studio (using the **WebApp.sln** file).
2. Create a [custom module class](https://docs.kentico.com/13/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code.md).
   - Add the class into a custom assembly (_Class Library_ project) within the solution.
3. Override the module's **OnInit** method and assign handlers to the **DocumentEvents.LogChange.Before** event.

   ```csharp

   using CMS;
   using CMS.Base;
   using CMS.DataEngine;
   using CMS.DocumentEngine;

   // Registers the custom module into the system
   [assembly: RegisterModule(typeof(LogChangeHandlerModule))]

   public class LogChangeHandlerModule : Module
   {
       // Module class constructor, the system registers the module under the name "LogChangeHandlers"
       public LogChangeHandlerModule()
           : base("LogChangeHandlers")
       {
       }

       // Contains initialization code that is executed when the application starts
       protected override void OnInit()
       {
           base.OnInit();

           // Assigns a handler to the DocumentEvents.LogChange.Before event
           // This event occurs when pages are modified, before the system starts logging the changes
           DocumentEvents.LogChange.Before += LogDocumentChange_Before;
       }
   }

   ```
4. Define the handler methods (inside the custom module class):

   ```csharp

   // Disables logging of staging and outgoing integration tasks for the content of pages in the /Archive section of the website
   private void LogDocumentChange_Before(object sender, LogDocumentChangeEventArgs e)
   {
       // Gets the synchronized page
       TreeNode page = e.Settings.Node;

       // Excludes pages under the "/Archive" path from content staging and integration bus synchronization
       if (page.NodeAliasPath.StartsWith("/Archive"))
       {
           e.Using(new CMSActionContext()
           {
               LogSynchronization = false,
               LogIntegration = false
           }
           );
       }
   }

   ```
5. Save the class and Rebuild the solution.

The custom handlers ensure that the system does not create synchronization tasks for the content and metadata of pages in the website's _/Archive_ section.

## Excluding content by handling synchronization tasks

[Content staging](https://docs.kentico.com/13/deploying-websites/content-staging.md) and the [integration bus](https://docs.kentico.com/13/integrating-3rd-party-systems/using-the-integration-bus.md) use synchronization tasks to transfer changes to the target server or application. You can cancel the creation of synchronization tasks during the following system events:

- **StagingEvents.LogTask.Before**
- **IntegrationEvents.LogInternalTask.Before**

Excluding content via the _LogTask_ events provides the following advantages and disadvantages:

- &#x20;Allows you to access the data of the synchronization task inside the event handler. For example, you can disable only specific types of synchronization tasks.
- &#x20;The system needs to prepare the synchronization data for every object/page change, which requires more overhead than when excluding content through [LogChange handlers](#excluding-content-by-handling-page-or-object-changes).

### Example

The following example demonstrates how to use the **LogTask** handler to disable content staging for the deletion of [role objects](https://docs.kentico.com/13/managing-users/role-management.md) and for content synchronization of certain pages.

1. Open your Xperience solution in Visual Studio (using the **WebApp.sln** file).
2. Create a [custom module class](https://docs.kentico.com/13/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code.md).
   - Add the class into a custom assembly (_Class Library_ project) within the solution.
3. Override the module's **OnInit** method and assign a handler to the **StagingEvents.LogTask.Before** event.

   ```csharp

   using CMS;
   using CMS.DataEngine;
   using CMS.Synchronization;
   using CMS.DocumentEngine;

   // Registers the custom module into the system
   [assembly: RegisterModule(typeof(LogTaskHandlerModule))]

   public class LogTaskHandlerModule : Module
   {
       // Module class constructor, the system registers the module under the name "LogTaskHandlers"
       public LogTaskHandlerModule()
           : base("LogTaskHandlers")
       {
       }

       // Contains initialization code that is executed when the application starts
       protected override void OnInit()
       {
           base.OnInit();

           // Assigns a handler to the StagingEvents.LogTask.Before event
           // This event occurs before the system creates content staging synchronization tasks
           StagingEvents.LogTask.Before += LogTask_Before;
       }
   }

   ```
4. Define the handler method (inside the custom module class):

   ```csharp

   private void LogTask_Before(object sender, StagingLogTaskEventArgs e)
   {
       // Handles content staging exclusion of documents
       if (e.Object is TreeNode)
       {
           // Gets the synchronized document
           TreeNode document = (TreeNode)e.Object;

           // Cancels the creation of content staging tasks for documents under the "/Archive" path
           if (document.NodeAliasPath.StartsWith("/Archive"))
           {
               e.Cancel();
           }
       }
       // Handles content staging exclusion of objects
       else
       {
           // Gets the synchronized object
           BaseInfo synchronizedObject = e.Object;

           // Gets the synchronization task
           StagingTaskInfo stagingTask = e.Task;

           // Cancels the creation of content staging tasks for the deletion of role objects
           if ((synchronizedObject.TypeInfo.ObjectType == CMS.Membership.RoleInfo.OBJECT_TYPE)
                && (stagingTask.TaskType == TaskTypeEnum.DeleteObject))
           {
               e.Cancel();
           }
       }
   }

   ```
5. Save the class and Rebuild the solution.

The handler ensures that the system does not create staging tasks:

- For changes made to pages in the website's _/Archive_ section
- When a role is deleted from the system
