---
title: Managing roles from the MVC application
related:
  - https://docs.kentico.com/13/managing-users/user-registration-and-authentication/integrating-xperience-membership.md
  - https://docs.kentico.com/13/managing-users/authorizing-live-site-actions-via-roles.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).

After you [integrate Xperience membership](https://docs.kentico.com/13/managing-users/user-registration-and-authentication/integrating-xperience-membership.md) into your MVC live site project, you can use the ASP.NET Identity API to add or remove Xperience [roles](https://docs.kentico.com/13/managing-users/role-management.md) for users. For example, this allows you to assign roles to new users immediately after [registration](https://docs.kentico.com/13/managing-users/user-registration-and-authentication/enabling-user-registration.md).

> **Info:** **Note**: If you only wish to manage roles manually, you do not need to write any code. Use the _Roles_ or _Users_ application in the Xperience administration interface (see [Role management](https://docs.kentico.com/13/managing-users/role-management.md)).

To use the available role management methods:

- Prepare a property that gets an instance of the **Kentico.Membership.KenticoUserManager** class for the current request – call _HttpContext.GetOwinContext().Get()_.
- Get the ID of the user whose roles you wish to manage (the methods require the ID as a parameter).

```csharp

using System.Web;

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;

using Kentico.Membership;


```

```csharp

        /// <summary>
        /// Provides access to the Kentico.Membership.KenticoUserManager instance.
        /// </summary>
        public KenticoUserManager KenticoUserManager
        {
            get
            {
                return HttpContext.GetOwinContext().Get<KenticoUserManager>();
            }
        }

        /// <summary>
        /// Gets the Kentico.Membership.User representation of the currently signed in user.
        /// You can use the object to access the user's ID, which is required by the role management methods.
        /// </summary>
        public User CurrentUser
        {
            get
            {
                return KenticoUserManager.FindByName(User.Identity.Name);
            }
        }


```

To add roles, call the **AddToRolesAsync** method of the _KenticoUserManager_ instance. You can add one or more roles, each specified by a separate string parameter (equal to the corresponding role name).

```csharp

                        // Attempts to assign the current user to the "KenticoRole" and "CMSBasicUsers" roles
                        IdentityResult addResult = await KenticoUserManager.AddToRolesAsync(CurrentUser.Id, "KenticoRole", "CMSBasicUsers");


```

To remove roles, call the **RemovesFromRolesAsync** method of the _KenticoUserManager_ instance. You can remove one or more roles, each specified by a separate string parameter.

```csharp

                    // Attempts to remove the "KenticoRole" and "CMSBasicUsers" roles from the current user
                    IdentityResult removeResult = await KenticoUserManager.RemoveFromRolesAsync(CurrentUser.Id, "KenticoRole", "CMSBasicUsers");


```

To check whether a user is in a given role, call the **IsInRoleAsync** method of the _KenticoUserManager_ instance.

```csharp

            // Checks whether the current user is assigned to the "KenticoRole" role
            if (await UserManager.IsInRoleAsync(CurrentUser.Id, "KenticoRole"))
            {
                // ...
            }


```

> **Note:** **Note**: You cannot use the ASP.NET Identity API to remove roles assigned to users indirectly through Xperience [memberships](https://docs.kentico.com/13/managing-users/membership-management.md).

> **Info:** **Managing membership data through the Xperience API**
>
> In addition to the ASP.NET Identity API, you can alternatively work with Xperience membership data using the API within the _CMS.Membership_ namespace (provided as part of the Kentico.Xperience.Libraries [integration package](https://docs.kentico.com/13/developing-websites/starting-with-mvc-development/installing-xperience-integration-packages.md)).
