Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael 8 posts 88 karma points
    Jul 24, 2022 @ 17:05
    Michael
    0

    ContentSavingNotification cancellation return error

    Hi,

    As I want to add validation during Document save, I create ContentSavingNotification as below:

        public class PageValidationNotificationHandler : INotificationHandler<ContentSavingNotification> {
    
    Public void Handle(ContentSavingNotification notification) {
          DoSomething();
         notification.CancelOperation(
                    new EventMessage(
                        "Publishing error",
                        "You cannot save this page with some reason",
                        EventMessageType.Error));
                notification.Cancel = true;
    }
    
    }
    

    When I run it, and user click save, it work and show the error message as well. But when user can click Save and Publish Umbraco return the error as below :

    Input string was not in a correct format.
    Exception Details
    System.FormatException, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e: Input string was not in a correct format.
    
    at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
       at System.Int32.Parse(String s, IFormatProvider provider)
       at Umbraco.Extensions.ContentExtensions.<>c.<GetAncestorIds>b__8_1(String s)
       at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
       at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.GetPublishedCulturesFromAncestors(IContent content)
       at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.AddDomainWarnings(IContent persistedContent, String[] culturesPublished, SimpleNotificationModel globalNotifications)
       at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.PostSaveInternal[TVariant](ContentItemSave contentItem, Func`3 saveMethod, Func`2 mapToDisplay)
       at 
    

    Can I know how to handle it which is not allow user save or publish the invalid page content.

    Thank you

Please Sign in or register to post replies

Write your reply to:

Draft