Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

If I cancel CreatingContent, the editor in edit mode doesn't see the the CancelReason

Vote:
 

Dear EpiServer Team,


I would like to forbid to create pages with word "TEST". I've implemented InitializationModule1 with:

        public void Initialize(InitializationEngine context)
        {
            ServiceLocator.Current.GetInstance<IContentEvents>().CreatingContent += new EventHandler<ContentEventArgs>(ForbidTestWord);
        }
        
        void ForbidTestWord(object sender, ContentEventArgs e)
        {
            if (e.Content.Name.ToUpper().Contains("TEST"))
            {
                e.CancelAction = true;
                e.CancelReason = "No chance, pick a better name";
            }
        }

And when I try to create page with word "test", I see the screen with no ability to create page,

and I do'nt see the CancelReason text "No chance, pick a better name".

 

 

What should I do to show to the editor the cancel reason on UI in edit mode?

#74541
Aug 30, 2013 16:47
Vote:
 

It seems, that for new content it's impossible to use e.CancelAction = true;

I looked at browser console and there is an errors:

POST http://localhost:88/Project/EPiServer/cms/Stores/contentdata/ 500 (Internal Server Error) dojo.js:15

stack: "Error: Unable to load /Project/EPiServer/cms/Stor….1.90/ClientResources/dtk/dojo/dojo.js:15:132189)",
message: "Unable to load /Project/EPiServer/cms/Stores/contentdata/ status: 500", response: Object, status: 500, responseText: "<!DOCTYPE html>
↵<html>
↵    <head>
↵        <titl…nStep step, Boolean& completedSynchronously)
↵-->"…}
message: "Unable to load /Project/EPiServer/cms/Stores/contentdata/ status: 500"
response: Object
responseText: "<!DOCTYPE html>
↵<html>
↵    <head>
↵        <title>New page could be created with current name.</title>
↵        <meta name="viewport" content="width=device-width" />
↵        <style>
↵         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
↵         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
↵         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
↵         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
↵         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
↵         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
↵         .marker {font-weight: bold; color: black;text-decoration: none;}
↵         .version {color: gray;}
↵         .error {margin-bottom: 10px;}
↵         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
↵         @media screen and (max-width: 639px) {
↵          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
↵         }
↵         @media screen and (max-width: 479px) {
↵          pre { width: 280px; }
↵         }
↵        </style>
↵    </head>

↵    <body bgcolor="white">

↵            <span><H1>Server Error in '/Project' Application.<hr width=100% size=1 color=silver></H1>

↵            <h2> <i>New page could be created only in &quot;en&quot; language brunch.</i> </h2></span>

↵            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

↵            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

↵            <br><br>

↵            <b> Exception Details: </b>EPiServer.Core.EPiServerCancelException: New page could be created only in &quot;en&quot; language brunch.<br><br>

↵            <b>Source Error:</b> <br><br>

↵            <table width=100% bgcolor="#ffffcc">
↵               <tr>
↵                  <td>
↵                      <code>

↵An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>

↵                  </td>
↵               </tr>
↵            </table>

↵            <br>

↵            <b>Stack Trace:</b> <br><br>

↵            <table width=100% bgcolor="#ffffcc">
↵               <tr>
↵                  <td>
↵                      <code><pre>

↵[EPiServerCancelException: New page could be created only in &quot;en&quot; language brunch.]
↵   EPiServer.Core.PageStoreBase.RaiseCancellablePageEvent(String key, String defaultReason, ContentEventArgs eventArgs) +255
↵   EPiServer.DataFactory.Save(IContent content, SaveAction action, AccessLevel access) +831
↵   EPiServer.IContentRepositoryExtension.Save(IContentRepository repository, IContent content, SaveAction action) +77
↵   EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.Create(ContentReference parentLink, Int32 contentTypeId, Nullable`1 resourceFolderId, String name, IDictionary`2 properties) +435
↵   EPiServer.Cms.Shell.UI.Rest.ContentDataStore.Post(PostContentModel entity) +465
↵   lambda_method(Closure , ControllerBase , Object[] ) +181
↵   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
↵   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211
↵   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
↵   System.Web.Mvc.&lt;&gt;c__DisplayClass13.&lt;InvokeActionMethodWithFilters&gt;b__10() +55
↵   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
↵   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
↵   EPiServer.Shell.Services.Rest.RestControllerBase.ExecuteCore() +252
↵   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
↵   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
↵   EPiServer.Shell.Services.Rest.RestHttpHandler.ProcessRequest(HttpContextBase httpContext) +451
↵   EPiServer.Shell.Services.Rest.RestHttpHandler.ProcessRequest(HttpContext context) +68
↵   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
↵   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +69
↵</pre></code>

↵                  </td>
↵               </tr>
↵            </table>

↵            <br>

↵            <hr width=100% size=1 color=silver>

↵            <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18045

↵            </font>

↵    </body>
↵</html>
↵<!--
↵[EPiServerCancelException]: New page could be created only in &quot;en&quot; language brunch.
↵   at EPiServer.Core.PageStoreBase.RaiseCancellablePageEvent(String key, String defaultReason, ContentEventArgs eventArgs)
↵   at EPiServer.DataFactory.Save(IContent content, SaveAction action, AccessLevel access)
↵   at EPiServer.IContentRepositoryExtension.Save(IContentRepository repository, IContent content, SaveAction action)
↵   at EPiServer.Cms.Shell.UI.Rest.ContentChangeManager.Create(ContentReference parentLink, Int32 contentTypeId, Nullable`1 resourceFolderId, String name, IDictionary`2 properties)
↵   at EPiServer.Cms.Shell.UI.Rest.ContentDataStore.Post(PostContentModel entity)
↵   at lambda_method(Closure , ControllerBase , Object[] )
↵   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
↵   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
↵   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
↵   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10()
↵   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
↵   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
↵   at EPiServer.Shell.Services.Rest.RestControllerBase.ExecuteCore()
↵   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
↵   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
↵   at EPiServer.Shell.Services.Rest.RestHttpHandler.ProcessRequest(HttpContextBase httpContext)
↵   at EPiServer.Shell.Services.Rest.RestHttpHandler.ProcessRequest(HttpContext context)
↵   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
↵   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
↵-->"
stack: "Error: Unable to load /Project/EPiServer/cms/Stores/contentdata/ status: 500↵    at Error (<anonymous>)↵    at new _30e (http://localhost:88/Project/EPiServer/Shell/2.1.90/ClientResources/dtk/dojo/dojo.js:15:76933)↵    at _4e7 [as handleResponse] (http://localhost:88/Project/EPiServer/Shell/2.1.90/ClientResources/dtk/dojo/dojo.js:15:131910)↵    at XMLHttpRequest._4f3 (http://localhost:88/Project/EPiServer/Shell/2.1.90/ClientResources/dtk/dojo/dojo.js:15:132189)"
status: 500
xhr: XMLHttpRequest
__proto__: TMP

#74917
Sep 11, 2013 15:05
Vote:
 

Thanks for the bug report. I have added the following bug to handle this:

Bug #105525: The UI does not handle the case that the creation was cancelled in an event handler

#74928
Sep 11, 2013 15:59
Vote:
 

Thank you.

#74933
Sep 11, 2013 16:24
Vote:
 

Have the bug been fixed? EpiServer 9. When we set the CancelAction as true  we get exceptions in browser console instead of messages. 

#147748
Apr 23, 2016 9:42
Vote:
 

Maybe you could use a custom validation attribute to solve this until the bug is fixed

#147751
Apr 24, 2016 10:53
Vote:
 

In the upcoming EPiServer.CMS.Core 9.11 you can implement a validator that only runs when content is being saved: IContentSaveValidation, this interface extends IValidate but also adds contextual information such as which save action that was used.

#150301
Jun 15, 2016 17:21
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.