0
我正在開發Umbraco 7 MVC應用程序,我的要求是在Umbraco內部添加項目。 商品名稱應該是唯一的。對於用下面的代碼,但我得到的錯誤「哎呀呀:本文件發佈,但不是在緩存(內部錯誤)」Umbraco unpublish事件不適用於當前節點
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication,
ApplicationContext applicationContext)
{
ContentService.Publishing += ContentService_Publishing;
}
private void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
try
{
if(newsItemExists)
{
e.Cancel = true;
}
}
catch (Exception ex)
{
e.Cancel = true;
Logger.Error(ex.ToString());
}
}
然後我嘗試添加代碼,以取消發佈,但它不工作即節點正在發佈。下面是我的代碼
private void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
try
{
int itemId=1234; //CurrentPublishedNodeId
if(newsItemExists)
{
IContent content = ContentService.GetById(itemId);
ContentService.UnPublish(content);
library.UpdateDocumentCache(item.Id);
}
}
catch (Exception ex)
{
e.Cancel = true;
Logger.Error(ex.ToString());
}
}
但與上面的代碼,如果你給CurrentPublishedNodeId = 2345 //正確someOthernodeId其未公佈。
你能幫我解決這個問題嗎?
謝謝你的回覆。我的客戶想要顯示錯誤消息,如「該項目存在」。我正在使用PublishedEntities獲取當前的頁面ID,我將刪除這個「library.UpdateDocumentCache」。在行IContent content = ContentService.GetById(itemId);如果我通過currentpublilshedNodeId它不工作,但如果我給其他節點Id然後它的工作。 –
你上面試過我的代碼嗎?不要使用currentPublishedNodeId。你也可以在這裏閱讀自定義消息:http://issues.umbraco.org/issue/U4-5927 - 現在有點可能,但有點不好意思,它在7.3.0本來就是可能的。 – sebastiaan