本文整理汇总了C#中N2.Web.Url.PrependSegment方法的典型用法代码示例。如果您正苦于以下问题:C# Url.PrependSegment方法的具体用法?C# Url.PrependSegment怎么用?C# Url.PrependSegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类N2.Web.Url
的用法示例。
在下文中一共展示了Url.PrependSegment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildUrl
/// <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 override string BuildUrl(ContentItem item)
{
if (item == null) throw new ArgumentNullException("item");
ContentItem current = item;
if (item.VersionOf.HasValue)
{
current = item.VersionOf;
}
// move up until first real page
while(current != null && !current.IsPage)
{
current = current.Parent;
}
// no start page found, use rewritten url
if (current == null) return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();
Url url;
if (host.IsStartPage(current))
{
// we move right up to the start page
url = "/";
}
else
{
// at least one node before the start page
url = new Url("/" + current.Name + current.Extension);
current = current.Parent;
// build path until a start page
while (current != null && !host.IsStartPage(current))
{
url = url.PrependSegment(current.Name);
current = current.Parent;
}
}
// no start page found, use rewritten url
if (current == null) return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();
if (item.IsPage && item.VersionOf.HasValue)
// the item was a version, add this information as a query string
url = url.AppendQuery(PathData.PageQueryKey, item.ID);
else if(!item.IsPage)
// the item was not a page, add this information as a query string
url = url.AppendQuery(PathData.ItemQueryKey, item.ID);
if (current.ID == host.CurrentSite.StartPageID)
{
// the start page belongs to the current site, use relative url
return Url.ToAbsolute("~" + url.PathAndQuery);
}
var site = host.GetSite(current.ID) ?? host.DefaultSite;
return GetHostedUrl(item, url, site);
}
示例2: BuildUrl
public string BuildUrl(ContentItem item)
{
Url url = new Url("/");
foreach (ContentItem parent in N2.Find.EnumerateParents(item, null, true))
{
if (true == parent["IsStartPage"] as bool?)
return url;
url = url.PrependSegment(parent.Name);
}
return url;
}
示例3: BuildUrl
/// <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 string BuildUrl(ContentItem item)
{
if (item == null) throw new ArgumentNullException("item");
ContentItem current = item;
if (item.VersionOf != null)
{
current = item.VersionOf;
}
// move up until first real page
while (current != null && !current.IsPage)
{
current = current.Parent;
}
// no page found, use rewritten url
if (current == null) throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item);
Url url;
if (host.IsStartPage(current))
{
// we move right up to the start page
url = "/";
}
else
{
// at least one node before the start page
url = new Url("/" + current.Name + current.Extension);
current = current.Parent;
// build path until a start page
while (current != null && !host.IsStartPage(current))
{
url = url.PrependSegment(current.Name);
current = current.Parent;
}
}
// no start page found, use rewritten url
if (current == null) return item.FindPath(PathData.DefaultAction).RewrittenUrl;
if (item.IsPage && item.VersionOf != null)
// the item was a version, add this information as a query string
url = url.AppendQuery(PathData.PageQueryKey, item.ID);
else if (!item.IsPage)
// the item was not a page, add this information as a query string
url = url.AppendQuery(PathData.ItemQueryKey, item.ID);
return Url.ToAbsolute("~" + url);
}