protected Url BuildPageUrl(ContentItem page, ref ContentItem current) { Url url = "/"; if (!host.IsStartPage(current)) { if (BuildingUrl != null) { // build path until a start page while (current != null && !host.IsStartPage(current)) { var args = new UrlEventArgs(current); BuildingUrl(this, args); if (!string.IsNullOrEmpty(args.Url)) { url = url.PrependSegment(Url.ToRelative(args.Url).TrimStart('~')); break; } url = url.PrependSegment(current.Name); current = current.Parent; } } else { while (current != null && !host.IsStartPage(current)) { url = url.PrependSegment(current.Name); current = current.Parent; } } url = url.SetExtension(page.Extension); } return(url); }
void parser_BuildingUrl(object sender, UrlEventArgs e) { var source = e.AffectedItem as IUrlSource; if (source == null || e.AffectedItem.ID == 0) return; if (string.IsNullOrEmpty(source.DirectUrl)) return; e.Url = source.DirectUrl; }
void parser_BuildingUrl(object sender, UrlEventArgs e) { var source = e.AffectedItem as IUrlSource; if (source == null || e.AffectedItem.ID == 0) { return; } if (string.IsNullOrEmpty(source.DirectUrl)) { return; } e.Url = source.DirectUrl; }
/// <summary>Calculates an item url by walking it's parent path.</summary> /// <param name="item">The item whose url to compute.</param> /// <returns>A friendly url to the supplied item.</returns> public virtual Url BuildUrl(ContentItem item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.VersionOf.HasValue) { ContentItem version = item.VersionOf; if (version != null) { return(BuildUrl(version) .SetQueryParameter(PathData.VersionQueryKey, item.VersionIndex)); } } else if (item.ID == 0) { var page = Find.ClosestPage(item); if (page != null && page != item) { return(BuildUrl(page) .SetQueryParameter(PathData.VersionQueryKey, page.VersionIndex) .SetQueryParameter("versionKey", item.GetVersionKey())); } } var current = Find.ClosestPage(item); // no page found, throw if (current == null) { throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item); } Url url = BuildPageUrl(current, ref current); if (current == null) { // no start page found, use rewritten url return(item.FindPath(PathData.DefaultAction).GetRewrittenUrl()); } if (!item.IsPage) { // the item was not a page, add this information as a query string url = url.AppendQuery(PathData.ItemQueryKey, item.ID); } var absoluteUrl = Url.ToAbsolute("~" + url); if (BuiltUrl != null) { var args = new UrlEventArgs(item) { Url = absoluteUrl }; BuiltUrl(this, args); return(args.Url); } else { return(absoluteUrl); } }
protected Url BuildPageUrl(ContentItem page, ref ContentItem current) { Url url = "/"; if (!host.IsStartPage(current)) { if (BuildingUrl != null) { // build path until a start page while (current != null && !host.IsStartPage(current)) { var args = new UrlEventArgs(current); BuildingUrl(this, args); if (!string.IsNullOrEmpty(args.Url)) { url = Url.ToRelative(args.Url).TrimStart('~').ToUrl().AppendSegment(url); //url = url.PrependSegment(Url.ToRelative(args.Url).TrimStart('~')); break; } url = url.PrependSegment(current.Name); current = current.Parent; } } else { while (current != null && !host.IsStartPage(current)) { url = url.PrependSegment(current.Name); current = current.Parent; } } url = url.SetExtension(page.Extension); } return url; }
/// <summary>Calculates an item url by walking it's parent path.</summary> /// <param name="item">The item whose url to compute.</param> /// <returns>A friendly url to the supplied item.</returns> public virtual Url BuildUrl(ContentItem item) { if (item == null) throw new ArgumentNullException("item"); if (item.VersionOf.HasValue) { ContentItem version = item.VersionOf; if (version != null) return BuildUrl(version).SetQueryParameter(PathData.VersionIndexQueryKey, item.VersionIndex); } else if (item.ID == 0) { var page = Find.ClosestPage(item); if (page != null && page != item) { return BuildUrl(page) .SetQueryParameter(PathData.VersionIndexQueryKey, page.VersionIndex) .SetQueryParameter("versionKey", item.GetVersionKey()); } } var current = Find.ClosestPage(item); // no page found, throw if (current == null) throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item); Url url = BuildPageUrl(current, ref current); if (current == null) // no start page found, use rewritten url return item.FindPath(PathData.DefaultAction).GetRewrittenUrl(); if (!item.IsPage) // the item was not a page, add this information as a query string url = url.AppendQuery(PathData.ItemQueryKey, item.ID); var absoluteUrl = Url.ToAbsolute("~" + url); if (BuiltUrl != null) { var args = new UrlEventArgs(item) { Url = absoluteUrl }; BuiltUrl(this, args); return args.Url; } else return absoluteUrl; }