2013-04-13 61 views
1

例如,在保存和發佈數據之前,我想操作數據(對數據進行處理),比如檢查數據,向UrlRewriting.config文件中添加一個較短的URL,並自動調整這些值。當我刪除或取消發佈節點時,我想自動從UrlRewriting.config文件中刪除較短的URL。 另一方面,我想完全控制在Umbraco後臺的保存,發佈和刪除過程。 請幫助我。如何在Umbraco後臺(管理面板)中自定義保存和發佈?

回答

4

如果要將URL更改爲節點,可以通過修改umbracoUrlAlias屬性輕鬆地完成此操作,而不是將條目添加到URLRewriting.config。

只要保存節點,發佈,刪除等時添加邏輯,您將要做的就是創建一個類,訂閱許多Umbraco events中的一個或多個並在那裏執行邏輯。有關更多詳細信息,請參見Application startup events & event registration

+0

我參觀http://soetemansoftware.nl/,我想下載http://www.soetemansoftware.nl/downloads/umbracoeventoverview.pdf。但它是破損。 – Jahan

+1

PDF的內容在該頁面上全部可用。如果您確實需要脫機版本,請複製並粘貼。 –

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) 
    { 
     ... 
    } 
} 
相關問題