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 playing around with ContentService class and I am trying to get this example working (it's from https://our.umbraco.com/documentation/Reference/Notifications/ContentService-Notifications):
public class DontShout : INotificationHandler<ContentPublishingNotification>
public void Handle(ContentPublishingNotification notification)
foreach (var node in notification.PublishedEntities)
var newsArticleTitle = node.GetValue<string>("title");
notification.CancelOperation(new EventMessage("Corporate style guideline infringement",
"Don't put the announcement title in upper case, no need to shout!",
I placed it in a test.cs file in the root of the project, but when I build the project and spins up the site again it seems not to work: I write "HEY" in the title field, but no notification turns up (except the "Content published: and is visible on the website" message).
You need to register your notification handlers in your startup too: https://our.umbraco.com/documentation/Reference/Notifications/#registering-notification-handlers-in-the-startup-class
Thanks - that makes sense.
But when I do that:
#pragma warning disable IDE0022 // Use expression body for methods
#pragma warning restore IDE0022 // Use expression body for methods
I get this error: "The type or namespace name 'ContentPublishingNotification' could not be found"
Should I add a using statement in Startup.cs - and what statement?
If you're in visual studio, put the cursor on the line where you add the handler, and press alt+enter, then it will suggest what you need 🙂
Fantastic - thanks! The "Show potential fixes" link helped me! :)
I was using VS Code (like the light weight feeling), but now I have a reason to use VS.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted