---
title: Applying customizations in the Xperience environment
related:
  - https://docs.kentico.com/13/custom-development/best-practices-for-customization.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).

With the Xperience [MVC](https://docs.kentico.com/13/developing-websites/mvc-development-overview.md) and [Core](https://docs.kentico.com/13/developing-websites/developing-xperience-applications-using-asp-net-core.md) development models, the live site application and administration application each have their own separate code base and project files. You can modify the system's functionality for both applications using the same customization API and endpoints described throughout the documentation.

However, customization of the administration application does not automatically apply to the live site application and vice versa. For every customization, you need to consider which applications should be affected and deploy your custom code accordingly:

- **Both applications** – in many cases, customizations need to cover both applications to work consistently. Typical examples are customizations of [e-commerce functionality](https://docs.kentico.com/13/e-commerce-features/customizing-on-line-stores/e-commerce-customization-model.md) or user-related actions, which can occur both on the live site and through the administration interface. See [Deploying custom code to both applications](#deploying-custom-code-to-both-applications).
- **Administration-only** – for customizations that modify or extend parts of the administration interface or only affect functionality triggered in the administration. For example, [extenders of UI elements](https://docs.kentico.com/13/custom-development/creating-custom-modules/creating-extenders-for-module-interface-pages.md) or [custom scheduled tasks](https://docs.kentico.com/13/configuring-xperience/scheduling-tasks/scheduling-custom-tasks.md).
- **Live site-only** – for customizations of actions that only occur on the live site. For example, code that adjusts the [contact recognition](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-contacts/configuring-contact-recognition.md) logic.

## Deploying custom code to both applications

We recommend using the following approach to deploy shared custom code to both the live site and administration applications:

1. [Add a custom assembly](https://docs.kentico.com/13/custom-development/adding-custom-assemblies.md) (_Class Library_ project) in one of the applications (under either the live site solution or the Xperience administration _WebApp.sln_ solution).
2. Create classes with the required custom code in the project.
3. Add the same project to the other application's solution.

   > **Note:** **Important**: When working with the Xperience administration solution, make sure that you do NOT install the _Kentico.Xperience.Libraries_ package into the _CMSApp_ project. The project already references Xperience DLLs in the solution's _Lib_ folder.

Having a project in both solutions ensures that changes are shared between the projects during development.

> **Info:** **Note**: After making changes in the shared project, you need to rebuild and potentially redeploy both the administration and live site applications (rebuilding just the solution where you made the changes is not sufficient).

If you also have customizations intended for only one of the applications, we recommend creating a separate _Class Library_ project in each solution. In this scenario, you can share individual code files between the projects by adding them as links in Visual Studio.

### Example

The following example demonstrates how to prepare a customization that automatically assigns new [users](https://docs.kentico.com/13/managing-users/user-management.md) to a default [role](https://docs.kentico.com/13/managing-users/role-management.md). Users can be created both in the administration interface and on the live site (registration of visitors), so the customization is deployed to both applications to ensure that it works consistently.

Start by adding the customization to the live site project:

1. Open your live site solution in Visual Studio.
2. [Add a custom assembly](https://docs.kentico.com/13/custom-development/adding-custom-assemblies.md) (_Class Library_ project) with class discovery enabled to the solution, or re-use an existing assembly. For example, name the project _**Custom**_.
3. Reference the _Custom_ project from your live site web project.
4. Create a new class under the custom project, for example named _**CustomUserModule**_ (the example uses an [event handler](https://docs.kentico.com/13/custom-development/handling-global-events.md) to extend the user functionality):

   ```csharp

   using CMS;
   using CMS.DataEngine;
   using CMS.Membership;
   using CMS.SiteProvider;

   // Registers the custom module into the system
   [assembly: RegisterModule(typeof(Custom.CustomUserModule))]

   namespace Custom
   {
       public class CustomUserModule : Module
       {
           // Module class constructor, the system registers the module under the name "CustomUsers"
           public CustomUserModule()
               : base("CustomUsers")
           {
           }

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

               // Assigns a handler to the Insert.After event of user objects
               UserInfo.TYPEINFO.Events.Insert.After += User_InsertAfterEventHandler;
           }

           // Handler method that runs when a new user object is created in the system
           private void User_InsertAfterEventHandler(object sender, ObjectEventArgs e)
           {
               if (e.Object != null)
               {
                   // Gets an info object representing the new user
                   UserInfo user = (UserInfo)e.Object;

                   // Gets the "DefaultRole" role
                   RoleInfo role = RoleInfo.Provider.Get("DefaultRole", SiteContext.CurrentSiteID);

                   if (role != null)
                   {
                       // Assigns the role to the user
                       UserInfoProvider.AddUserToRole(user.UserName, role.RoleName, SiteContext.CurrentSiteName);
                   }
               }
           }
       }
   }

   ```
5. Save all changes and **Rebuild** the solution.

Now add the customization to your Xperience administration project:

1. Open your Xperience administration solution in Visual Studio (using the _WebApp.sln_ file).
2. Right-click the solution in the **Solution Explorer** and select **Add -> Existing Project**.
3. Navigate to the _Custom_ folder in the web project and select the _Custom.csproj_ file.
4. Click **Open**.
5. Reference the _Custom_ project from the administration web project (_CMSApp_).
6. Save all changes and **Rebuild** the solution.

The customization is now applied to both applications. The shared custom project allows you to keep changes in the custom code synchronized between the applications during development. When a new user registers on the live site or is created manually in the administration interface, they are automatically assigned to the _DefaultRole_ role (you need to create a role with this code name).
