protected static void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); if (args.IsPostBack) { if (!args.HasResult) { return; } string results = args.Result; AjaxScriptManager ajaxScriptManager = Client.AjaxScriptManager; if (string.IsNullOrEmpty(results)) { ajaxScriptManager.Alert("Enter an old URL and a new URL for the new redirect."); return; } string[] values = results.Split('|'); var oldValue = values[1]; var newValue = values[2]; var siteName = values[3]; if (Regex.IsMatch(oldValue, Data.Constants.HostNameRegex)) { SheerResponse.Alert(Translate.Text("Only partial URLs are allowed in the Old URL field.")); ShowModal(args); } var repository = new Repository("sitecore_master_index"); if (!repository.RedirectExists(oldValue, siteName)) // check if the old redirect exists here { try { //values[1] = values[1].Replace("%20", " "); repository.Insert(siteName, oldValue, newValue, MainUtil.GetBool(Convert.ToInt32(values[0]), false)); ajaxScriptManager.Dispatch("redirectmanager:refresh"); return; } catch (Exception exception) { ajaxScriptManager.Alert(Translate.Text("An error occured while creating the redirect for\"\":\n\n{1}", new object[] { values[1], exception.Message })); ShowModal(args); } } SheerResponse.Alert(Translate.Text("A redirect with the old URL \"{0}\" already exists.", new object[] { values[1] }), new string[0]); } ShowModal(args); }
/// <summary> /// Handles the recording of the new record into the Sitecore database. /// </summary> /// <param name="args">The pipeline args</param> protected static void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); if (!args.IsPostBack) { ShowModal(args); return; } if (!args.HasResult) { return; } string results = args.Result; AjaxScriptManager ajaxScriptManager = Client.AjaxScriptManager; if (string.IsNullOrEmpty(results)) { ajaxScriptManager.Alert("Enter an old URL and a new URL for the new redirect."); return; } string[] values = results.Split('|'); var candidate = new MarketingRedirect { IsPermanent = MainUtil.GetBool(Convert.ToInt32(values[0]), false), OldUrl = values[1].ToLower().Trim(), NewUrl = values[2].ToLower().Trim(), SiteName = values[3] }; var repository = new Repository(Sitecore.Context.ContentDatabase, "sitecore_master_index"); if (repository.CandidateOldUrlContainsHostname(candidate)) { SheerResponse.Alert(Translate.Text("Only partial URLs are allowed in the Old URL field.")); ShowModal(args); return; } if (!repository.CandidateIsUnique(candidate)) { SheerResponse.Alert( Translate.Text("A redirect with the old URL \"{0}\" already exists.", new object[] { candidate.OldUrl }), new string[0]); ShowModal(args); return; } if (repository.CandidateTargetIsRedirect(candidate)) { SheerResponse.Alert("This redirect is invalid because the new URL provided would also be redirected due to another rule in this system. The New URL must resolve to a published page."); ShowModal(args); return; } if (!repository.CandidateTargetReturnsHttpSuccessResponse(candidate, out var status)) { SheerResponse.Alert(status.Message); ShowModal(args); return; } try { repository.Insert(candidate.SiteName, candidate.OldUrl, candidate.NewUrl, candidate.IsPermanent); Thread.Sleep(250); // If we don't do this, the refresh call won't work. ajaxScriptManager.Dispatch("redirectmanager:refresh"); } catch (Exception exception) { ajaxScriptManager.Alert(Translate.Text("An error occurred while creating the redirect for\"\":\n\n{1}", new object[] { values[1], exception.Message })); ShowModal(args); } }
/// <summary> /// Handles the process of committing record changes to the Sitecore database. /// </summary> /// <param name="args">the pipeline args.</param> protected void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); AjaxScriptManager ajaxScriptManager = Client.AjaxScriptManager; if (args.IsPostBack) { if (!args.HasResult) { return; } string results = args.Result; if (string.IsNullOrEmpty(results)) { ajaxScriptManager.Alert("Enter an old URL and a new URL for the new redirect."); return; } string[] values = results.Split('|'); var changes = new MarketingRedirect(); changes.ItemId = new ID(args.Parameters["ID"]); changes.IsPermanent = MainUtil.GetBool(Convert.ToInt32(values[0]), false); changes.OldUrl = values[1].ToLower().Trim(); changes.NewUrl = values[2].ToLower().Trim(); changes.SiteName = values[3]; if (Repository.CandidateOldUrlContainsHostname(changes)) { SheerResponse.Alert(Translate.Text("Only partial URLs are allowed in the Old URL field.")); return; } if (!Repository.CandidateIsUnique(changes)) { SheerResponse.Alert( Translate.Text("A redirect with the old URL \"{0}\" already exists.", new object[] { values[1] }), new string[0]); return; } if (Repository.CandidateTargetIsRedirect(changes)) { SheerResponse.Alert("The destination URL of this redirect is also a redirect. New URL must point to a page."); return; } if (!Repository.CandidateTargetReturnsHttpSuccessResponse(changes, out var status)) { SheerResponse.Alert(status.Message); return; } try { Repository.Update(changes); Thread.Sleep(250); // If we don't do this, the refresh call might not work. ajaxScriptManager.Dispatch("redirectmanager:refresh"); } catch (Exception exception) { ajaxScriptManager.Alert( Translate.Text("An error occured while creating the redirect for\"\":\n\n{1}", new object[] { values[1], exception.Message })); } } else { ajaxScriptManager.Alert("Are you sure you want to Edit this redirect?"); UrlString editRedirectUrl = new UrlString("/sitecore/shell/~/xaml/Sitecore.SitecoreModule.Shell.Redirect.EditRedirect.aspx"); editRedirectUrl.Parameters["ID"] = args.Parameters["ID"]; SheerResponse.ShowModalDialog(editRedirectUrl.ToString(), "780", "350", string.Empty, true); args.WaitForPostBack(); } }
protected void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); AjaxScriptManager ajaxScriptManager = Client.AjaxScriptManager; if (args.IsPostBack) { ID id = new ID(args.Parameters["ID"]); //int id = Convert.ToInt32(strid); if (!args.HasResult) { return; } string results = args.Result; if (string.IsNullOrEmpty(results)) { ajaxScriptManager.Alert("Enter an old URL and a new URL for the new redirect."); return; } //results = HttpUtility.HtmlEncode(results); string[] values = results.Split('|'); var oldValue = values[1]; var newValue = values[2]; var siteName = values[3]; if (Regex.IsMatch(oldValue, Data.Constants.HostNameRegex)) { SheerResponse.Alert(Translate.Text("Only partial URLs are allowed in the Old URL field.")); return; } if (!Repository.CheckUrlExists(id, oldValue, siteName)) // check if the old redirect exists here { try { //values[1] = values[1].Replace("%20", " "); Repository.Update(id, siteName, oldValue, newValue, MainUtil.GetBool(Convert.ToInt32(values[0]), false)); ajaxScriptManager.Dispatch("redirectmanager:refresh"); return; } catch (Exception exception) { ajaxScriptManager.Alert( Translate.Text("An error occured while creating the redirect for\"\":\n\n{1}", new object[] { values[1], exception.Message })); } } SheerResponse.Alert( Translate.Text("A redirect with the old URL \"{0}\" already exists.", new object[] { values[1] }), new string[0]); } else { ajaxScriptManager.Alert("Are you sure you want to Edit this redirect?"); UrlString editRedirectUrl = new UrlString("/sitecore/shell/~/xaml/Sitecore.SitecoreModule.Shell.Redirect.EditRedirect.aspx"); editRedirectUrl.Parameters["ID"] = args.Parameters["ID"]; SheerResponse.ShowModalDialog(editRedirectUrl.ToString(), "780", "350", string.Empty, true); args.WaitForPostBack(); } }