---
title: Restrict content types in properties
slug: cms-12/docs/restricting-content-types-in-properties
createdAt: 2026-08-10T15:56:02.000Z
---

## Restrict a `ContentArea`

The `AllowedTypes` attribute (placed in the `EPiServer.DataAnnotations` namespace, `EPiServer` assembly) are applied to a properties.

The following examples do not require an array declaration

```csharp
[AllowedTypes(new [] {
  typeof (PageData)
})]
public virtual ContentArea RelatedContentArea {
  get;
  set;
}

[AllowedTypes(typeof (PageData))]
public virtual ContentArea OtherRelatedContentArea {
  get;
  set;
}
```

The same attribute can also be set as:

```csharp
[AllowedTypes(AllowedTypes = new [] {
  typeof (PageData)
})]
public virtual ContentArea RelatedContentArea {
  get;
  set;
}
```

When an item that is  *part* of the allowed types is dragged over this property, the property is highlighted, and the editor can add the item to the property. But if the editor tries to drag another item that is *not part* of the allowed types, the property is grayed out, and the item cannot be added. The content selector dialog is also filtered out accordingly. Through the **Create a new block** link in the content area, editors can only add allowed item types.

You can specify several allowed types and inherited types:

```csharp
[AllowedTypes(new [] {
  typeof (PageData), typeof (BlockData)
})]
public virtual ContentArea RelatedContentArea {
  get;
  set;
}

[AllowedTypes(typeof (PageData), typeof (BlockData))]
public virtual ContentArea OtherRelatedContentArea {
  get;
  set;
}
```

## Restrict a certain set of types but allow others

The `AllowedTypes` attribute can also be used to restrict certain types from a larger pool of types.
For example, if you supply two arrays of types as constructor arguments, the first array argument considers allowed items, while the second argument considers restricted items.

```csharp
[AllowedTypes(new [] {
  typeof (BlockData)
}, new [] {
  typeof (EditorialBlock)
})]
public virtual ContentArea RelatedContentArea {
  get;
  set;
}
```

or

```csharp
[AllowedTypes(AllowedTypes = new [] {
  typeof (BlockData)
}, RestrictedTypes = new [] {
  typeof (EditorialBlock)
})]
public virtual ContentArea RelatedContentArea {
  get;
  set;
}
```

In this case, you can add `BlockData` items to the content area except the `EditorialBlock`, which is a `BlockData` but also part of restricted types. When an editor drags the `EditorialBlock`, or its subtypes, the content area is grayed out. Similarly, when an editor clicks the **Create a new block** link, the content selector is filtered out accordingly.

## Restrict based on base classes and interfaces

When you place the `AllowTypes` attribute on a `ContentArea`, `ContentReference` or a list of `ContentReference` property, the UI not only allows and restricts based on the given type's subtypes. For example:

```csharp
[AllowedTypes(new [] {
  typeof (SiteBlockData)
})]
public virtual ContentArea RelatedContentArea {
  get;
  set;
}
```

In this case, the property not only adds the `SiteBlockData` but other types inherited from the `SiteBlockData` also behave the same.

However, if you want to allow and restrict based on an interface, you must implement the `UIDescriptor` for the interface.

```csharp
interface ISpecialInterface { } 
public class SpecialBlock : BlockData, ISpecialInterface {}
```

If you now want to enable a content area to add blocks (except the ones inherited from the `ISpecialInterface`), you first have to implement a `UIDescriptor` for the `ISpecialInterface`.

```csharp
[UIDescriptorRegistration]
public class SpecialInterfaceDescriptor : UIDescriptor<ISpecialInterface> { }
```

Additionally, the interface has to inherit from the `IContentData` interface.

```csharp
public interface ISpecialInterface: IContentData {
  // properties and methods
}
```

After that, place the `AllowedTypes` on the content area property.

```csharp
[AllowedTypes(AllowedTypes = new [] {
    typeof (BlockData)
  },
  RestrictedTypes = new [] {
    typeof (ISpecialInterface)
  })]
public virtual ContentArea SomeArea {
  get;
  set;
}
```

This code adds blocks to `SomeArea` but restricts blocks that implement `ISpecialInterface`.

## Restrict content reference properties

The `AllowedTypes` attribute can be used for `ContentReference` or list of `ContentReference` properties as well:

```csharp
[AllowedTypes(typeof (ProductPage))]
public virtual ContentReference SomeLink {
  get;
  set;
}

[AllowedTypes(typeof (ProductPage))]
public virtual IList<ContentReference> SomeLinks {
  get;
  set;
}
```

This code results in the same behavior for content areas when dragging items to the property. You can add only `ProductPage` items to the property. Items not allowed (according to the `AllowedTypes` attribute) are not selectable in the content selector dialog.

## Hide allowed types description

By default, CMS displays a description of the allowed and restricted types under a property in the editing view. This description helps editors understand which content types to add. To hide this description, apply the `AllowedTypesUiSettings` attribute and set `HidePropertyAllowedTypesInformation` to true.

```csharp
[AllowedTypes(typeof (PageData))]
[AllowedTypesUiSettings(HidePropertyAllowedTypesInformation = true)]
public virtual ContentArea RelatedContentArea {
  get;
  set;
}
```

When `HidePropertyAllowedTypesInformation` is true, CMS still enforces the type restrictions, but editors do not see the description text. Set the value to `false`, or omit the attribute, to display the description.

## Known limitations

- `AllowedTypes` only works with `ContentArea`, `ContentReference` and list of `ContentReference` properties.
- `RestrictedTypes` always win. That means that if an item (a class or an interface) is given in `RestrictedTypes`, its instances and sub-items are restricted whether or not the item or sub-items exist in `AllowedTypes`.
