当用户发布或删除页面时如何执行自定义代码
How can I execute custom code when user publishes or deletes a page
我想在用户发布或删除页面时 运行 一些代码。执行此操作的最佳方法是什么?
我有一个自定义索引服务,可以搜索 html 内容,所以当用户在 Umbraco 中发布页面时,我想向该服务提交新内容。另外,我想在用户删除或分页时向索引服务提交删除。
创建一个class并继承自Application EventHandler
在 OnApplicationStarting 你可以创建各种事件
像这样
public class ApplicationEventHandler : IApplicationEventHandler
{
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Saving += ContentService_Saved;
ContentService.Published += ContentService_Published;
ContentService.UnPublishing +=ContentServiceOnUnPublishing;
ContentService.Deleting += ContentServiceOnDeleting;
ContentService.Moved +=ContentServiceOnMoved;
MediaService.Saving+=MediaService_Saving;
MemberService.Created+=MemberServiceOnCreated;
MemberService.Deleting += MemberServiceOnDeleted;
}
void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
}
我想在用户发布或删除页面时 运行 一些代码。执行此操作的最佳方法是什么?
我有一个自定义索引服务,可以搜索 html 内容,所以当用户在 Umbraco 中发布页面时,我想向该服务提交新内容。另外,我想在用户删除或分页时向索引服务提交删除。
创建一个class并继承自Application EventHandler 在 OnApplicationStarting 你可以创建各种事件
像这样
public class ApplicationEventHandler : IApplicationEventHandler
{
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Saving += ContentService_Saved;
ContentService.Published += ContentService_Published;
ContentService.UnPublishing +=ContentServiceOnUnPublishing;
ContentService.Deleting += ContentServiceOnDeleting;
ContentService.Moved +=ContentServiceOnMoved;
MediaService.Saving+=MediaService_Saving;
MemberService.Created+=MemberServiceOnCreated;
MemberService.Deleting += MemberServiceOnDeleted;
}
void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
}