public List<InboundRule> GetInboundRules() { if (db == null) { return null; } var redirectFolderItems = GetRedirectFolderItems(); if (redirectFolderItems == null) { return null; } var inboundRules = new List<InboundRule>(); foreach (var redirectFolderItem in redirectFolderItems) { Log.Debug(this, db, "Loading Inbound Rules from RedirectFolder: {0}", redirectFolderItem.Name); var folderDescendants = redirectFolderItem.Axes.GetDescendants() .Where(x => x.TemplateID == new ID(new Guid(SimpleRedirectItem.TemplateId)) || x.TemplateID == new ID(new Guid(InboundRuleItem.TemplateId))); foreach (var descendantItem in folderDescendants) { if (descendantItem.TemplateID == new ID(new Guid(SimpleRedirectItem.TemplateId))) { var simpleRedirectItem = new SimpleRedirectItem(descendantItem); Log.Debug(this, db, "Loading SimpleRedirect: {0}", simpleRedirectItem.Name); var inboundRule = CreateInboundRuleFromSimpleRedirectItem(simpleRedirectItem, redirectFolderItem); if (inboundRule != null && inboundRule.Enabled) { inboundRules.Add(inboundRule); } } else if (descendantItem.TemplateID == new ID(new Guid(InboundRuleItem.TemplateId))) { var inboundRuleItem = new InboundRuleItem(descendantItem); Log.Debug(this, db, "Loading InboundRule: {0}", inboundRuleItem.Name); var inboundRule = CreateInboundRuleFromInboundRuleItem(inboundRuleItem, redirectFolderItem); if (inboundRule != null && inboundRule.Enabled) { inboundRules.Add(inboundRule); } } } } return inboundRules; }
public List<InboundRule> GetInboundRules() { if (db == null) { return null; } var urlRewriteFolderItemId = new ID("{0DA6100D-E4FB-4ADD-AD4C-373F410A1952}"); var redirectFolderItem = db.GetItem(urlRewriteFolderItemId); //GetRedirectFolderItems(); if (redirectFolderItem == null) { return null; } var inboundRules = new List<InboundRule>(); Log.Info(this, db, "Loading Inbound Rules from RedirectFolder: {0}", redirectFolderItem.Name); var folderDescendants = redirectFolderItem.Axes.GetDescendants() .Where(x => x.TemplateID == new ID(new Guid(SimpleRedirectItem.TemplateId)) || x.TemplateID == new ID(new Guid(InboundRuleItem.TemplateId))); foreach (var descendantItem in folderDescendants) { if (descendantItem.TemplateID == new ID(new Guid(SimpleRedirectItem.TemplateId))) { var simpleRedirectItem = new SimpleRedirectItem(descendantItem); Log.Info(this, db, "Loading SimpleRedirect: {0}", simpleRedirectItem.Name); var inboundRule = CreateInboundRuleFromSimpleRedirectItem(simpleRedirectItem, redirectFolderItem); if (inboundRule != null && inboundRule.Enabled) { inboundRules.Add(inboundRule); } } else if (descendantItem.TemplateID == new ID(new Guid(InboundRuleItem.TemplateId))) { var inboundRuleItem = new InboundRuleItem(descendantItem); Log.Info(this, db, "Loading InboundRule: {0}", inboundRuleItem.Name); var inboundRule = CreateInboundRuleFromInboundRuleItem(inboundRuleItem, redirectFolderItem); if (inboundRule != null && inboundRule.Enabled) { inboundRules.Add(inboundRule); } } } return inboundRules; }
internal InboundRule CreateInboundRuleFromSimpleRedirectItem(SimpleRedirectItem simpleRedirectItem, RedirectFolderItem redirectFolderItem) { var inboundRulePattern = string.Format("^{0}/?$", simpleRedirectItem.Path.Value); var siteNameRestriction = GetSiteNameRestriction(redirectFolderItem); var redirectTo = simpleRedirectItem.Target; string actionRewriteUrl; Guid? redirectItem; string redirectItemAnchor; GetRedirectUrlOrItemId(redirectTo, out actionRewriteUrl, out redirectItem, out redirectItemAnchor); Log.Debug(this, simpleRedirectItem.Database, "Creating Inbound Rule From Simple Redirect Item - {0} - id: {1} actionRewriteUrl: {2} redirectItem: {3}", simpleRedirectItem.Name, simpleRedirectItem.ID.Guid, actionRewriteUrl, redirectItem); var inboundRule = new InboundRule { Action = new Redirect { AppendQueryString = true, Name = "Redirect", StatusCode = RedirectStatusCode.Permanent, RewriteUrl = actionRewriteUrl, RewriteItemId = redirectItem, RewriteItemAnchor = redirectItemAnchor, StopProcessingOfSubsequentRules = false, HttpCacheability = HttpCacheability.NoCache }, SiteNameRestriction = siteNameRestriction, Enabled = simpleRedirectItem.BaseEnabledItem.Enabled.Checked, IgnoreCase = true, ItemId = simpleRedirectItem.ID.Guid, ConditionLogicalGrouping = LogicalGrouping.MatchAll, Name = simpleRedirectItem.Name, Pattern = inboundRulePattern, MatchType = MatchType.MatchesThePattern, Using = Using.RegularExpressions }; return inboundRule; }