例如,在保存和发布数据之前,我想操作数据(处理数据),例如检查数据,在 UrlRewriting.config 文件中添加更短的 URL 并自动喜欢这些。当我删除或取消发布节点时,我想要自动从 UrlRewriting.config 文件中删除较短的 URL。另一方面,我希望完全控制 Umbraco 后台的保存、发布和删除过程。 请帮我。
问问题
3152 次
2 回答
4
如果您想更改节点的 URL,您可以通过修改umbracoUrlAlias
属性轻松地做到这一点,而不是在 URLRewriting.config 中添加条目。
至于在保存、发布、删除节点等时添加逻辑,您要做的是创建一个订阅多个Umbraco 事件中的一个或多个事件并在那里执行逻辑的类。有关更多详细信息,请参阅应用程序启动事件和事件注册。
于 2013-04-13T20:33:40.167 回答
3
以下是一些示例:
public class SaveAndPublish : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// Content Service
ContentService.Created += ContentService_Created;
ContentService.Saving += ContentService_Saving;
ContentService.Published += ContentService_Published;
ContentService.Trashing += ContentService_Trashing;
// Media Service
MediaService.Saving += MediaService_Saving;
MediaService.Saved += MediaService_Saved;
MediaService.Trashing += MediaService_Trashing;
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ContentService_Created(IContentService sender, NewEventArgs<IContent> e)
{
...
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
{
...
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
...
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ContentService_Trashing(IContentService sender, MoveEventArgs<IContent> e)
{
...
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MediaService_Saving(IMediaService sender, SaveEventArgs<IMedia> e)
{
...
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MediaService_Saved(IMediaService sender, SaveEventArgs<IMedia> e)
{
foreach (var entity in e.SavedEntities)
{
...
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MediaService_Trashing(IMediaService sender, MoveEventArgs<IMedia> e)
{
...
}
}
于 2014-10-15T00:59:22.317 回答