public virtual void UpdateRedirect(RedirectEntry entry) { using (RedirectorDbContext db = new RedirectorDbContext()) { db.RedirectEntries.Attach(entry); db.Entry <RedirectEntry>(entry).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public override void Process(HttpRequestArgs args) { Assert.ArgumentNotNull(args, "args"); string url = args.Context.Request.Url.PathAndQuery; // if ItemResolver failed to find an Item if (((Context.Item == null) && string.IsNullOrEmpty(Context.Page.FilePath)) || url.Contains("404;")) { // extract 404 url if (url.Contains("404;")) { url = Regex.Replace(HttpUtility.UrlDecode(url), ".*404;(.*)", "$1"); } // find an Item Redirect RedirectEntry redirect = RedirectManager.GetRedirect(Sitecore.Context.GetSiteName(), url); if (redirect != null) { UrlString newUrl = null; Item item = Context.Database.GetItem(new ID(redirect.ItemID)); if (item != null) { UrlOptions options = LinkManager.GetDefaultUrlOptions(); newUrl = new UrlString(LinkManager.GetItemUrl(item, options)); } if (newUrl != null && !string.IsNullOrEmpty(redirect.QueryString)) { var qsParameters = StringUtil.ParseNameValueCollection(redirect.QueryString, '&', '='); foreach (string key in qsParameters.AllKeys) { newUrl[key] = qsParameters[key]; } } // avoid looping if (newUrl != null && string.Compare(url, newUrl.ToString(), true) != 0) { args.AbortPipeline(); RedirectUtils.Do301Redirect(args.Context.Response, newUrl.ToString()); } } // no Item redirect found, try a NotFoundRule else if (url != null) { NotFoundRule rule = RedirectManager.ResolveRedirectRule(Sitecore.Context.GetSiteName(), url); if (rule != null) { ExecuteRule(url, rule, args); } } } }
public RedirectGridEntry(RedirectEntry entry) { Database db = Sitecore.Context.ContentDatabase; Item item = db.GetItem(new ID(entry.ItemID)); if (item != null) { this.EntryId = entry.RedirectEntryId.ToString(); this.ItemIcon = Themes.MapTheme(item.Appearance.Icon); this.Site = entry.Site; this.OldPath = entry.OldPath; this.NewPath = item.Paths.ContentPath; this.QueryString = entry.QueryString; } }
public virtual void CreateRedirect(string site, string oldPath, ID itemId, string queryString) { DeleteRedirect(site, oldPath); using (RedirectorDbContext db = new RedirectorDbContext()) { var redirect = new RedirectEntry() { RedirectEntryId = Guid.NewGuid(), Site = site, OldPath = oldPath, ItemID = itemId.ToGuid(), QueryString = queryString }; db.RedirectEntries.Add(redirect); db.SaveChanges(); } }
public override void Execute(CommandContext context) { Assert.ArgumentNotNull(context, "context"); ClientPipelineArgs args = new ClientPipelineArgs(); ListString list = new ListString(context.Parameters["entryids"]); bool isNew = context.Parameters["new"] == "1"; if (list.Items.Any() && !isNew) { Guid entryId = MainUtil.GetGuid(list.Items.FirstOrDefault(), Guid.Empty); if (entryId != Guid.Empty) { RedirectEntry entry = RedirectManager.GetRedirect(entryId); if (entry != null) { args.Parameters["entryid"] = entryId.ToString(); args.Parameters["oldpath"] = entry.OldPath; args.Parameters["itemid"] = entry.ItemID.ToString(); args.Parameters["querystring"] = entry.QueryString; args.Parameters["site"] = entry.Site; } } } ContinuationManager current = ContinuationManager.Current; if (current != null) { current.Start(this, "Run", args); } else { Context.ClientPage.Start(this, "Run", args); } }
protected void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); if (args.IsPostBack) { if (args.HasResult && args.Result != "undefined") { UrlString results = new UrlString(args.Result); Database db = Sitecore.Context.ContentDatabase; Guid entryId = MainUtil.GetGuid(args.Parameters["entryid"], Guid.Empty); Item item = db.GetItem(HttpUtility.UrlDecode(results["itemid"])); string oldPath = HttpUtility.UrlDecode(results["oldpath"]); string querystring = HttpUtility.UrlDecode(results["querystring"]); string site = HttpUtility.UrlDecode(results["site"]); if (item != null) { string siteName = site;// RedirectManager.ResolveSiteName(item); if (entryId != Guid.Empty) { RedirectEntry entry = RedirectManager.GetRedirect(entryId); if (entry != null) { entry.ItemID = item.ID.ToGuid(); entry.OldPath = oldPath; entry.QueryString = querystring; entry.Site = siteName; RedirectManager.UpdateRedirect(entry); } } else { RedirectManager.CreateRedirect(siteName, oldPath, item.ID, querystring); } } Client.AjaxScriptManager.Dispatch("redirects:refresh"); } } else { UrlString url = new UrlString(UIUtil.GetUri("control:EditRedirectForm")); if (!string.IsNullOrEmpty(args.Parameters["itemid"])) { url["itemid"] = args.Parameters["itemid"]; } if (!string.IsNullOrEmpty(args.Parameters["oldpath"])) { url["oldpath"] = args.Parameters["oldpath"]; } if (!string.IsNullOrEmpty(args.Parameters["querystring"])) { url["querystring"] = args.Parameters["querystring"]; } if (!string.IsNullOrEmpty(args.Parameters["site"])) { url["site"] = args.Parameters["site"]; } SheerResponse.ShowModalDialog(url.ToString(), true); args.WaitForPostBack(); } }
public static void UpdateRedirect(RedirectEntry entry) { Provider.UpdateRedirect(entry); }