---
title: Adding custom fields to users
related:
  - https://docs.kentico.com/k12sp/managing-users/user-management.md
  - https://docs.kentico.com/k12sp/managing-users/user-registration-and-authentication/integrating-kentico-membership.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).

Custom fields can help you store and organize additional data related to [users](https://docs.kentico.com/k12sp/managing-users/user-management.md). For example, if you need to gather data not collected in the system by default, add custom fields and use them to store any additional information required.

This page describes how to:

- [Add custom fields to user objects](#adding-custom-fields-to-users)
- [Access the added fields from the Kentico.Membership ASP.NET Identity implementation](#accessing-custom-user-fields-in-kenticos-asp.net-identity-implementation)

## Adding custom fields to users

Custom fields may store values such as text, date and time, and boolean values. To define custom fields:

1. Open the **Modules** application.
2. **Edit** () the **Membership** module.
3. Switch to the **Classes** tab.
4. **Edit** () the **User** class.
5. Switch to the **Fields** tab.
6. Create new fields based on your requirements using the [field editor](https://docs.kentico.com/k12sp/custom-development/developing-form-controls/reference-field-editor.md).
7. Click **Save**.

You have added custom fields for the user object in Kentico. In the administration interface, added custom fields are displayed on a separate **Custom fields** tab when editing users in the **Users** application.

## Accessing custom user fields in Kentico's ASP.NET Identity implementation

> **Note:** **Hotfix 12.0.34 or newer required**
>
> The Kentico membership API used in this scenario is available after installing [hotfix 12.0.34](https://devnet.kentico.com/download) or newer. The _UserManager_, _UserStore_, and _SignInManager_ non-generic types existing in prior versions are still usable and work with the default _User_ object.

Kentico [MVC applications](https://docs.kentico.com/k12sp/developing-websites/mvc-development-overview.md) use an implementation of the [ASP.NET Identity](https://docs.microsoft.com/en-us/aspnet/identity/overview/getting-started/introduction-to-aspnet-identity) membership system and the OWIN standard (provided in the  _Kentico.Membership_ namespace, see [Integrating Kentico membership](https://docs.kentico.com/k12sp/managing-users/user-registration-and-authentication/integrating-kentico-membership.md) for detailed information). 

By default, the implementation uses the   **Kentico.Membership.User**  type to represent users. Objects of this type wrap  _CMS.Membership.UserInfo_  objects (which represent the user in Kentico), and facilitate the transfer of user data between the Identity implementation and internal Kentico logic. 

If you defined any custom user fields that you wish to handle via _Kentico.Membership_  types (e.g., when creating or updating user information, performing authentication or authorization, etc.), you need to ensure proper mapping between the  _UserInfo_  object and the _User_  object.

1. Open the MVC project in Visual Studio.
2. Create a new class that inherits from _Kentico.Membership.User._
3. Declare properties that correspond to the custom fields you specified in the [administration interface](#adding-custom-fields-to-users). 

   > **Info:** Besides exposing custom fields added to the user object via the administration interface, you can also expose existing fields of the user object that are not accessible by default via the _Kentico.Membership.User_ type. For example, the _MiddleName_ user field or advanced user fields from the _UserSettings_ class. See the sample **ExtendedUser** class below for an example.
4. Override the **MapFromUserInfo** and **MapToUserInfo** methods and:
   - Call the base implementation of the methods. This maps all properties of the _Kentico.Membership.User_ class such as _FirstName_ a&#x6E;_&#x64;_ _Email._
   - Get and set values of the custom properties you wish to have available using **UserInfo.GetValue** and **UserInfo.SetValue**. 

     ```csharp title="Declaring an ExtendedUser class that extends the default Kentico.Membership.User object"

     using CMS.Membership;

     using Kentico.Membership;

     namespace MembershipCustomization
     {
         // Extends the default Kentico.Membership.User object
         public class ExtendedUser : User
         {
             // Exposes the existing 'MiddleName' property of the 'UserInfo' object
             public string MiddleName
             {
                 get;
                 set;
             }

             // Property that corresponds to a custom field specified in the administration interface
             public string CustomField
             {
                 get;
                 set;
             }

             // Ensures field mapping between Kentico's user objects and the Kentico.Membership ASP.NET Identity implementation
             // Called when retrieving users from Kentico via Kentico.Membership.KenticoUserManager<TUser>
             public override void MapFromUserInfo(UserInfo source)
             {
                 // Calls the base class implementation of the MapFromUserInfo method
                 base.MapFromUserInfo(source);

                 // Maps the 'MiddleName' property to the extended user object
                 MiddleName = source.MiddleName;

                 // Sets the value of the 'CustomField' property
                 CustomField = source.GetValue<string>("CustomField", null);
             }

             // Ensures field mapping between Kentico's user objects and the Kentico.Membership ASP.NET Identity implementation
             // Called when creating or updating users using Kentico.Membership.KenticoUserManager<TUser>
             public override void MapToUserInfo(UserInfo target)
             {
                 // Calls the base class implementation of the MapToUserInfo method
                 base.MapToUserInfo(target);

                 // Maps the 'MiddleName' property to the target 'UserInfo' object
                 target.MiddleName = MiddleName;

                 // Sets the value of the 'CustomField' custom user field
                 target.SetValue("CustomField", CustomField);
             }
         }
     }

     ```
5. In the [Owin startup pipeline](https://docs.kentico.com/k12sp/managing-users/user-registration-and-authentication/integrating-kentico-membership.md), register new or add additional _KenticoUserManager_, _KenticoUserStore_, and _KenticoSignInManager_ types from the _Kentico.Membership_ namespace. The types need to specify the extended user object as their generic parameter (_ExtendedUser_ in this case). Register these generic types instead of the original _Manager_ and _Store_ types (which do not have the _Kentico_ prefix).

   ```csharp

   using Owin;

   using CMS.SiteProvider;

   using Kentico.Membership;

   public partial class Startup
   {
       public void Configuration(IAppBuilder app)
       {
           // Registers Kentico.Membership Identity types with the 'ExtendedUser' user object
           app.CreatePerOwinContext(() => KenticoUserManager<ExtendedUser>.Initialize(app, new KenticoUserManager<ExtendedUser>(new KenticoUserStore<ExtendedUser>(SiteContext.CurrentSiteName))));
           app.CreatePerOwinContext<KenticoSignInManager<ExtendedUser>>(KenticoSignInManager<ExtendedUser>.Create);

           ...
       }
   }

   ```
6. When retrieving the registered types from the Owin context via **HttpContext.GetOwinContext().Get**, retrieve the type with the associated generic parameter, for example:

   ```csharp

   KenticoSignInManager<ExtendedUser> KenticoSignInManager = HttpContext.GetOwinContext().Get<KenticoSignInManager<ExtendedUser>>();

   ```

   This ensures that you retrieve the type capable of working with the extended user object.

The _Kentico.Membership_ Identity implementation is now able to work with the extended user object together with any additional properties and logic it contains.
