HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback

## Restricting a ContentArea

The AllowedTypes attribute (placed in the EPiServer.DataAnnotations namespace, EPiServer assembly) can be applied to a property.

The same attribute can also be set as:

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 editor tries to drag another item which is **not part** of allowed types, the property is grayed out, and the item can't 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 as well as inherited types:

## Restricting a certain set of types but allowing all others

The AllowedTypes attribute can also be used to restrict a certain set of 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.


In this case, all BlockData items can be added 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 sub types, the content area is grayed out. Similarly, when an editor clicks the **Create a new block** link, the content selector is filtered out accordingly.

## Restriction based on base classes and interfaces

Once you place the AllowTypes attribute on a ContentArea, ContentReference or ContentReferenceList property, the user interface not only allows and restricts based on the given type but also on all of the given type's sub types. For example:

In this case, the property not only allows the SiteBlockData to be added but all 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.

If you now want to enable a content area to allow all blocks to be added except the ones inherited from the ISpecialInterface, you first have to implement a UIDescriptor for the ISpecialInterface.

Additionally, the interface has to inherits from IContentData interface.

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

This code allows all blocks to be added to SomeArea but restricts blocks that implement ISpecialInterface.

## Restricting content reference properties

The AllowedTypes attribute can be used for ContentReference or ContentReferenceList properties as well:

This code results in the same behavior as for content areas when dragging items to the property; that is, only items of the type _ProductPage_ can be added to the property. Items not allowed (according to the AllowedTypes attribute) are not selectable in the content selector dialog.

## Known limitations

  • AllowedTypes only works with ContentArea, ContentReference and ContentReferenceList type properties.

  • RestrictedTypes always win. That means that if an item (a class or an interface) is given in RestrictedTypes, all of its instances and sub items are restricted whether or not the item or sub items exist in AllowedTypes.