CancelOperation throws exception from Custom event handler
I am using Umbraco 7.8.1
I have added custom event handler to prevent saving data to validate future dates in date picker
ContentService.Saving += delegate (IContentService sender, SaveEventArgs<IContent> args)
{
foreach (var content in args.SavedEntities.Where(c => c.ContentType.Alias.Equals("profile")))
{
var birthDate = Convert.ToDateTime(content.Properties["birthDate"].Value);
if (DateTime.Compare(birthDate ,DateTime.Now) > 0)
{
args.CancelOperation(new EventMessage("Invalid Date of Birth", "You can not add futuer date...", EventMessageType.Error));
}
}
}
It shows error message but it also throws an exception
Umbraco.Web.Editors.ContentController - Unhandled controller exception occurred
System.Web.Http.HttpResponseException: Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.
Not saying this will work, but there is an alternate way to do this...
First, you need to check whether the event supports cancelling and then you can perform the same logic using:
if (DateTime.Compare(birthDate, DateTime.Now) > 0)
{
if (args.CanCancel)
{
args.Cancel = true;
args.Messages.Add(new EventMessage("Invalid Date of Birth", "You can not add futuer date...", EventMessageType.Error));
}
}
As I say, it may not help, but worth a try.
The other thing to do is create a breakpoint in VS and step through to see what might be happening.
CancelOperation throws exception from Custom event handler
I am using Umbraco 7.8.1
I have added custom event handler to prevent saving data to validate future dates in date picker
It shows error message but it also throws an exception
Umbraco.Web.Editors.ContentController - Unhandled controller exception occurred System.Web.Http.HttpResponseException: Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.
and then page redirect to url : http://domain.in/umbraco/#/content/content/edit/0
Please help me to fix this problem.
Not saying this will work, but there is an alternate way to do this...
First, you need to check whether the event supports cancelling and then you can perform the same logic using:
As I say, it may not help, but worth a try.
The other thing to do is create a breakpoint in VS and step through to see what might be happening.
is working on a reply...