例如,在保存和发布数据之前,我想要操作数据(数据处理),例如检查数据,将URL缩短到UrlRewriting.config文件并自动更新。当我删除或取消发布节点时,我想自动从UrlRewriting.config文件中删除较短的URL。 另一方面,我希望完全控制Umbraco后台的保存,发布和删除过程。 请帮我。
答案 0 :(得分:4)
如果要更改节点的URL,可以通过修改umbracoUrlAlias
属性轻松实现,而不是向URLRewriting.config添加条目。
在保存,发布,删除等节点时添加逻辑,您要做的是创建一个订阅多个Umbraco events中的一个或多个的类并在那里执行逻辑。有关详细信息,请参阅Application startup events & event registration。
答案 1 :(得分: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)
{
...
}
}