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


C# Url.Append方法代码示例

本文整理汇总了C#中N2.Web.Url.Append方法的典型用法代码示例。如果您正苦于以下问题:C# Url.Append方法的具体用法?C# Url.Append怎么用?C# Url.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在N2.Web.Url的用法示例。


在下文中一共展示了Url.Append方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateProductLink

        public string GenerateProductLink(long? productId, out object matchingProductPage)
        {
            string ret;
            var cacheKey = string.Format("{0} {1} {2} {3}",
                WebSession.Current.SiteId, WebSession.Current.LanguageCode, "ProductLink", productId);
            if (!_urlCache.TryGet(cacheKey, out ret))
            {
                try
                {
                    var prodPages = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot<ProductPage>();
                    if (prodPages.All(pp => !string.IsNullOrEmpty(pp.ProductID)))
                    {
                        // find a product page from the root level that has no product ID
                        var page = CmsFinder.FindAllNonSiteDescendentsOfRoot<ProductPage>()
                                            .LastOrDefault(pp => string.IsNullOrEmpty(pp.ProductID));

                        if (page != null)
                            prodPages.Add(page);
                    }

                    var targetProductPage =
                        prodPages.FirstOrDefault(
                            pp => pp.ProductID.Split().Any(pid => pid.Equals(productId.ToString(), StringComparison.InvariantCultureIgnoreCase))) ??
                        prodPages.LastOrDefault(pp => pp.ProductID.Length == 0);

                    if (targetProductPage == null)
                        ret = null;
                    else
                    {
                        var url = new Url(GetNormalizedPageUrl(targetProductPage));

                        if ((string.IsNullOrEmpty(targetProductPage.ProductID) || targetProductPage.ProductID.Split().Length > 1)
                            && productId != null)
                            url = url.Append(productId.ToString());

                        ret = url.ToString();
                    }

                    AddCache(cacheKey, ret, targetProductPage);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Unable to create product link for product {0}", productId);
                }
            }

            _itemCache.TryGet(cacheKey, out matchingProductPage);

            return ret;
        }
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:50,代码来源:LinkGenerator.cs

示例2: GenerateInterstitialLink

        public string GenerateInterstitialLink(long? productId)
        {
            string ret;
            var cacheKey = string.Format("{0} {1} {2} {3}",
                WebSession.Current.SiteId, WebSession.Current.LanguageCode, "InterstitialLink", productId);
            if (!_urlCache.TryGet(cacheKey, out ret))
            {
                try
                {
                    var interstitialPages = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot<ShoppingCartInterstitialPage>();
                    var targetInterstitialPage =
                        interstitialPages.FirstOrDefault(
                            ip => ip.ProductID.Split().Any(pid => pid.Equals(productId.ToString(), StringComparison.InvariantCultureIgnoreCase)));

                    if (targetInterstitialPage == null)
                        ret = null;
                    else
                    {
                        var url = new Url(GetNormalizedPageUrl(targetInterstitialPage));

                        if ((string.IsNullOrEmpty(targetInterstitialPage.ProductID) || targetInterstitialPage.ProductID.Split().Length > 1)
                            && productId != null)
                            url = url.Append(productId.ToString());

                        ret = url.ToString();
                    }

                    AddCache(cacheKey, ret);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Unable to create shopping cart interstitial link for product {0}", productId);
                }
            }

            return ret;
        }
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:37,代码来源:LinkGenerator.cs

示例3: GenerateCategoryLink

        public string GenerateCategoryLink(long? categoryId, bool? forceListPage, out object matchingCategoryPage)
        {
            //~~  a cheap and nasty chaos monkey
            //if (DateTime.Now.Minute % 2 == 1)
            //    throw new Exception("chaos happened " + categoryId);
            //~~

            string ret;
            var cacheKey = string.Format("{0} {1} {2} {3} {4}",
                WebSession.Current.SiteId, WebSession.Current.LanguageCode, "CategoryLink", categoryId, forceListPage);
            if (!_urlCache.TryGet(cacheKey, out ret))
            {
                var catPages = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot<CatalogPage>();

                if (catPages.All(cps => cps.CategoryID.Length != 0))
                {
                    // find a category page from the root level that has no category ID
                    var defaultCatPage = CmsFinder.FindAllNonSiteDescendentsOfRoot<CatalogPage>()
                             .LastOrDefault(cps => cps.CategoryID.Length == 0);

                    if (defaultCatPage != null)
                        catPages.Add(defaultCatPage);
                }

                CatalogPage cp;

                if (forceListPage.HasValue && forceListPage.Value)
                    cp = catPages.LastOrDefault(catalogPage => catalogPage.CategoryID.Length == 0);
                else
                    cp = catPages.FirstOrDefault(catalogPage => catalogPage.CategoryID.Equals(categoryId.ToString(), StringComparison.InvariantCultureIgnoreCase)) ??
                             catPages.LastOrDefault(catalogPage => catalogPage.CategoryID.Length == 0);

                if (cp == null)
                    ret = null;
                else
                {
                    // If the category page came from the root, append it's name and parameters to the current page's url
                    var url = new Url(GetNormalizedPageUrl(cp));

                    if (string.IsNullOrEmpty(cp.CategoryID) && categoryId != null)
                        url = url.Append(categoryId.Value.ToString(CultureInfo.InvariantCulture));

                    if (forceListPage.HasValue && forceListPage.Value && string.IsNullOrEmpty(cp.CategoryID))
                        url = url.AppendQuery("list=true");

                    ret = url.ToString();
                }

                AddCache(cacheKey, ret, cp);
            }

            _itemCache.TryGet(cacheKey, out matchingCategoryPage);

            return ret;
        }
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:55,代码来源:LinkGenerator.cs


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