Hello,
Interesting... Maybe try use events handler ?
for example:
using CMS.Base;
using CMS.DocumentEngine;
using System;
[CustomDocumentEvents]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the loading of custom handlers.
/// </summary>
private class CustomDocumentEvents : CMSLoaderAttribute
{
/// <summary>
/// The system executes the Init method of the CMSModuleLoader attributes when the application starts.
/// </summary>
public override void Init()
{
// Assigns custom handlers to events
DocumentEvents.Insert.Before += DocumentInsert_Before;
}
private void DocumentInsert_Before(object sender, DocumentEventArgs e)
{
var doc = e.Node;
if (doc == null) return;
if (doc.ClassName != "pageclassname") return;
var quanity = DocumentHelper.GetDocuments(doc.ClassName)
.WhereLike("NodeAliasPath", e.TargetParentNode.NodeAliasPath)
//others conditions
.Count;
if (quanity > 1)
throw new Exception("Only single instance of this page type is allowed in this location!");
}
}
}