/// <summary>Invokes an event and and executes an action unless the event is cancelled.</summary> /// <param name="preHandlers">The event handler to signal.</param> /// <param name="item">The item affected by this operation.</param> /// <param name="sender">The source of the event.</param> /// <param name="finalAction">The default action to execute if the event didn't signal cancel.</param> public static void InvokeEvent(EventHandler <CancellableItemEventArgs> preHandlers, ContentItem item, object sender, Action <ContentItem> finalAction, EventHandler <ItemEventArgs> postHandlers) { if (preHandlers != null && (VersionsTriggersEvents || !item.VersionOf.HasValue)) { CancellableItemEventArgs args = new CancellableItemEventArgs(item, finalAction); preHandlers.Invoke(sender, args); if (!args.Cancel) { args.FinalAction(args.AffectedItem); if (postHandlers != null) { postHandlers(sender, args); } } } else { finalAction(item); if (postHandlers != null) { postHandlers(sender, new ItemEventArgs(item)); } } }
void securityEnforcer_AuthorizationFailed(object sender, CancellableItemEventArgs e) { string returnUrl = context.Url.LocalUrl; string loginUrl = null; // Custom login page: var startPage = parser.StartPage as Models.StartPage; if (startPage != null && !string.IsNullOrWhiteSpace(startPage.LoginPage)) { loginUrl = startPage.LoginPage; } // Default login page: if (loginUrl == null) { string loginPageToken = "{Account.Login.PageUrl}"; string loginPageUrl = loginPageToken.ResolveUrlTokens(); if (loginPageUrl != loginPageToken) { loginUrl = loginPageUrl; } } if (loginUrl != null) { e.Cancel = true; context.HttpContext.Response.Redirect(Url.Parse(loginUrl).AppendQuery("returnUrl", returnUrl)); } }
void securityEnforcer_AuthorizationFailed(object sender, CancellableItemEventArgs e) { var startPage = parser.StartPage as Models.StartPage; if (startPage != null && startPage.LoginPage != null) { e.Cancel = true; context.HttpContext.Response.Redirect(Url.Parse(startPage.LoginPage).AppendQuery("returnUrl", context.Url.LocalUrl)); } }
void Persister_ItemSaving(object sender, CancellableItemEventArgs e) { foreach (var cd in e.AffectedItem.Details) { if(cd.StringValue != null) { if(cd.StringValue.Contains("script")) { throw new Exception("The demo site does not allow scripts to be entered."); } } } }
/// <summary>Invokes an event and and executes an action unless the event is cancelled.</summary> /// <param name="handler">The event handler to signal.</param> /// <param name="item">The item affected by this operation.</param> /// <param name="sender">The source of the event.</param> /// <param name="finalAction">The default action to execute if the event didn't signal cancel.</param> public static void InvokeEvent(EventHandler <CancellableItemEventArgs> handler, ContentItem item, object sender, Action <ContentItem> finalAction) { if (handler != null && (VersionsTriggersEvents || item.VersionOf == null)) { CancellableItemEventArgs args = new CancellableItemEventArgs(item, finalAction); handler.Invoke(sender, args); if (!args.Cancel) { args.FinalAction(args.AffectedItem); } } else { finalAction(item); } }
void securityEnforcer_AuthorizationFailed(object sender, CancellableItemEventArgs e) { var url = new Url("{ManagementUrl}/Login.aspx").ResolveTokens(); url.AppendQuery("returnUrl", _context.Url.LocalUrl); _context.HttpContext.Response.Redirect(url); }