防止在 umbraco 中删除具有子节点的内容
我想防止内容节点在有子节点时被丢弃。我像这样设置了一个事件处理程序:
public class KeepSafeEvents : ApplicationBase
{
public KeepSafeEvents()
{
Document.BeforeMoveToTrash += new Document.MoveToTrashEventHandler(Document_BeforeMoveToTrash);
}
void Document_BeforeMoveToTrash(Document sender, umbraco.cms.businesslogic.MoveToTrashEventArgs e)
{
if (sender.HasChildren)
{
e.Cancel = true;
}
}
}
但是,这似乎不起作用。我认为这是因为删除过程在处理父节点(然后没有子节点)之前首先将子节点移动到垃圾箱。还有其他可能的解决方案吗?或者我在上面犯了一个简单的错误?
I would like to prevent content nodes from being trashed if they have any children. I setup an event handler like so:
public class KeepSafeEvents : ApplicationBase
{
public KeepSafeEvents()
{
Document.BeforeMoveToTrash += new Document.MoveToTrashEventHandler(Document_BeforeMoveToTrash);
}
void Document_BeforeMoveToTrash(Document sender, umbraco.cms.businesslogic.MoveToTrashEventArgs e)
{
if (sender.HasChildren)
{
e.Cancel = true;
}
}
}
However, this doesn't seem to work. I assume it is because the delete process moves the child nodes to trash first before dealing with the parent node (which then has no children). Is there another possible solution? Or am I making a simple mistake above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码非常适合我。您确定已将生成的 .dll 文件复制到 Umbraco 的 /bin 文件夹中吗?
我只是写得比你短一点,如下所示,但功能应该完全相同。
我确实注意到带有子节点的文档似乎被删除(它从树中消失),但是当您重新加载树时,该节点仍然存在。
This code works perfectly for me. Are you sure that you've copied the resulting .dll file to Umbraco's /bin folder?
I just wrote it a little shorter than you did, like below, but the functionality should be exactly the same.
I do notice that the document with childnode seems to get deleted (it disappears from the tree), but when you reload the tree, the node is still there.