Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am trying to use ContentService.Saved to be able to take action whenever a node is saved in the back end.
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
//ContentService.Publishing += ContentServicePublishing;
ContentService.Saved += ContentServiceSaved;
private void ContentServiceSaved(IContentService sender, SaveEventArgs<IContent> e)
foreach (var node in e.SavedEntities)
if (node.ContentType.Alias == "post")
The only problem i find is that when I visit a page (not through the backend), the ContentServiceSaved method gets called. Am i wrong to assume that this should only get called on save in the back end? I wouldn't expect it to be called when the actual page is visited.
Can someone clarify? Or help?
I wouldn't expect that either, and haven't experienced this before. How can you tell that the ContentServiceSaved method is getting called? Are you 100% sure?
My first guess is that on page load some/all of your pages save some sort of data using the ContentService.
Do all of your pages call ContentServiceSaved(...)? Or just a couple of them? Try doing a site wide search for ContentService to see if there is some place in your site that you are pragmatically saving content.
Let me know. I'm curious about this one. Sounds pretty strange.
I'm positive it gets called, as it hits the breakpoint when I run in VS.
And with your comment about guessing...that some sort of save is occurring when the page is loaded ...the struck something.
I DO save when a page is loaded as I'm doing some sort of 'page visited' counter which updates the pagevisit property on a page and saves it on page load!
That is TOTALLY it I'm sure.
Question is - would there be a way I could tell when a node is published via code vs via the backend?
I'd like to be able to filter my actions based on where the save was triggered.
Please please please do NOT hold a counter on your document that saves every time you visit a page! Not only is it going to make the page load slow it is also creating a new version for that document, re-saving all of the properties you have on the page. When you go live with this site you will see the database grow very quickly and perfomance go down a lot.
I recommend you implement a counter by creating your own database table and log visits there.
And to answer your last question: there's no way to tell if a node is saved from the backoffice or through some other way, making the above advice even more applicable. :)
Altough yeah a counter on content, not all that good a pattern.
As to knowing whether backoffice user saved or not... doesn't the contentService save have an authenticating admin user associated with the call?
If so then just have an umbraco user for your coded front end saves to authenticate against, and check for that user as the last updater to distinguish between front end and back office?
Yes, but all saves have an admin associated with it and sure you can create a "fake" user and pass that on when saving on the frontend.
But again: Please don't do it, it's going to be a world of hurt.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted