当前位置: 首页>>代码示例>>C#>>正文


C# Url.PrependSegment方法代码示例

本文整理汇总了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);
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:62,代码来源:MultipleHostsUrlParser.cs

示例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;
 }
开发者ID:n2cms,项目名称:N2Contrib,代码行数:11,代码来源:FakeUrlParser.cs

示例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);
        }
开发者ID:joaohortencio,项目名称:n2cms,代码行数:54,代码来源:UrlParser.cs


注:本文中的N2.Web.Url.PrependSegment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。