Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Restrict Content Area only to add Links


How to Restrict Content Area only to add Links?

Aug 13, 2020 12:00

What do you mean?

Allow links to pages, but not adding blocks?

Aug 13, 2020 13:16

Hi Tanvi,

Can you please explain it more?

Like -do you want to add a specific block in the ContentArea?

Aug 13, 2020 13:19

Yes I want to add only Links to Pages in the ContentArea 

Aug 13, 2020 13:22

ok, then I think AllowedTypes is the best way to do this-

[AllowedTypes(new []{ typeof(YourPageType) })]
public virtual ContentArea Gallery { get; set; }
Edited, Aug 13, 2020 13:28

You have several options.

1. Add an AllowedTypes attribute to your property


2. Use LinkItemCollection instead of ContentArea

 public virtual LinkItemCollection MyLinkProperty{ get; set; }

3. Use List of ContentReference

public virtual IList<ContentReference> MyContentListProperty{ get; set; }
Edited, Aug 13, 2020 13:29

I'm using ContentArea as I want only specific page links. I dont want to add links for all types of pages.

Can u suggest any code which can restrict the pagetype links to only specific ones in LinkItemCollection?

Aug 13, 2020 13:35

If you are going to use LinkItemCollection, have a look at this:

Aug 13, 2020 13:37

Hi Tanvi,

Please use `Restriction based on base classes and interfaces` to restrict the page and block type contents:

Aug 13, 2020 14:55

I tried [AllowedTypes(typeof(PageData))] but this is allowing the entire pagetype.

I want it to be in form of links. [AllowedTypes(typeof(ContentReference))] is not working.

Is there any other way to add ContentReference in the ContentArea

Aug 13, 2020 16:59

Tanvi, please pass the page types that you want to include in allowed types. Like below ex-

[AllowedTypes(new []{ typeof(YourPageType A), typeof(YourPageType B),
typeof(YourPageType C)})]
public virtual ContentArea Gallery { get; set; }
Aug 13, 2020 17:52

I'm not what rules you need, but using IValidate lets you be very specific, if restricting by page type is not enough. You could only allow links to pages with a name starting with the letter «C» or pages that are created Friday after 5PM. Or anything else you may think of.

Aug 14, 2020 4:24
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.