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


C# UrlString.Remove方法代码示例

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


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

示例1: AddLatestVersionToUrlString

 /// <summary>
 /// Overide Sitecore choosing which version to open and get the latest instead
 /// </summary>
 /// <param name="urlString">Raw Url String</param>
 /// <param name="itemId">Id of the Item that will have the its version checked</param>
 private static void AddLatestVersionToUrlString(UrlString urlString, string itemId)
 {
     urlString.Remove(Util.Constants.VersionQueryStringKeyName);
     urlString.Add(Util.Constants.VersionQueryStringKeyName, Context.ContentDatabase.GetItem(itemId).Versions.GetLatestVersion().Version.ToString());
 }
开发者ID:udt1106,项目名称:Sitecore-Item-Buckets,代码行数:10,代码来源:AddSilentTab.cs

示例2: ReplaceMediaUrl

        /// <summary>
        /// Rewrites media urls to point to CDN hostname and dehydrates querystring into filename
        /// </summary>
        /// <param name="inputUrl">/path/to/file.ext?a=1&b=2</param>
        /// <returns>http://cdnHostname/path/to/file!cf!a=1!b=2.ext</returns>
        public virtual string ReplaceMediaUrl(string inputUrl, string cdnHostname)
        {
            // string versionKey = inputUrl + "_v";
            // string updatedKey = inputUrl + "_d";
            string cachedKey = string.Concat(WebUtil.GetScheme(), inputUrl);
            try
            {
                string cachedUrl = this._cache.GetUrl(cachedKey);

                if (!string.IsNullOrEmpty(cachedUrl))
                {
                    return cachedUrl;
                }

                // ignore fully qualified urls or data:
                if (WebUtil.IsExternalUrl(inputUrl) || inputUrl.StartsWith("data:") || inputUrl.StartsWith("//"))
                {
                    return inputUrl;
                }

                UrlString url = new UrlString(WebUtil.NormalizeUrl(inputUrl));
                UrlString originalUrl = new UrlString(WebUtil.NormalizeUrl(inputUrl));

                // if the stoptoken ex. ?nfc=1  is non-empty, don't replace this url
                if (!string.IsNullOrEmpty(url[this.StopToken]))
                {
                    url.Remove(this.StopToken);
                }
                else
                {
                    if (!string.IsNullOrEmpty(cdnHostname))
                    {
                        url.HostName = cdnHostname; // insert CDN hostname
                    }

                    if (CDNSettings.MatchProtocol)
                    {
                        url.Protocol = WebUtil.GetScheme();
                    }

                    url.Path = StringUtil.EnsurePrefix('/', url.Path);  // ensure first "/" before ~/media

                    if (CDNSettings.FilenameVersioningEnabled)
                    {
                        // NOTE: DOREL CHANGE: THIS CHANGE IS NEEDED TO ADDING PARAMS TO MEDIA THAT HAVE "/~/media/"
                        string mediaLinkPrefixWithDash = Settings.Media.MediaLinkPrefix.Replace("~", "-");
                        string mediaLinkPrefixWithTilde = Settings.Media.MediaLinkPrefix.Replace("-", "~");

                        // NOTE: DOREL CHANGE: use url.Path instead of inputUrl, because url.Path already start with "/" anyway (because of previous EnsurePrefix)
                        // if this is a media library request
                        if (url.Path.Contains(mediaLinkPrefixWithDash) || url.Path.Contains(mediaLinkPrefixWithTilde))
                        {
                            string version = url["vs"] ?? string.Empty;
                            string updated = string.Empty;

                            // get sitecore path of media item
                            string mediaItemPath = this.GetMediaItemPath(url.Path);
                            if (!string.IsNullOrEmpty(mediaItemPath) && Sitecore.Context.Database != null)
                            {
                                Item mediaItem = string.IsNullOrEmpty(version)
                                                     ? Sitecore.Context.Database.SelectSingleItem(mediaItemPath)
                                                     : Sitecore.Context.Database.GetItem(mediaItemPath, Sitecore.Context.Language, Sitecore.Data.Version.Parse(version));

                                if (mediaItem == null)
                                {
                                    // no change to url
                                    url = originalUrl;
                                }
                                else
                                {
                                    // do not replace url if media item isn't public or requires Analytics processing
                                    // keep local url for this case
                                    if (!this.IsMediaPubliclyAccessible(mediaItem) || this.IsMediaAnalyticsTracked(mediaItem))
                                    {
                                        // no change to url
                                        url = originalUrl;
                                    }
                                    else
                                    {
                                        version = mediaItem.Version.Number.ToString();

                                        // NOTE: DOREL CHANGE: if media item doesn't have corresponding language version, then get statistic from existing language version
                                        if (!mediaItem.Statistics.Updated.Equals(DateTime.MinValue))
                                        {
                                            updated = DateUtil.ToIsoDate(mediaItem.Statistics.Updated);
                                        }
                                        else
                                        {
                                            Language languageInternational = LanguageManager.GetLanguage("en");

                                            Item mediaItemInternational = string.IsNullOrEmpty(version)
                                                     ? Sitecore.Context.Database.GetItem(mediaItemPath, languageInternational)
                                                     : Sitecore.Context.Database.GetItem(mediaItemPath, languageInternational, Sitecore.Data.Version.Parse(version));

                                            if (mediaItemInternational != null && !mediaItemInternational.Statistics.Updated.Equals(DateTime.MinValue))
//.........这里部分代码省略.........
开发者ID:vlukanin,项目名称:SitecoreCDN,代码行数:101,代码来源:CDNProvider.cs

示例3: AddLatestVersionToUrlString

 /// <summary>
 /// Overide Sitecore choosing which version to open and get the latest instead
 /// </summary>
 /// <param name="urlString">Raw Url String</param>
 /// <param name="itemId">Id of the Item that will have the its version checked</param>
 private static void AddLatestVersionToUrlString(UrlString urlString, string itemId, string language)
 {
     try
     {
         urlString.Remove(Util.Constants.VersionQueryStringKeyName);
         urlString.Add(Util.Constants.VersionQueryStringKeyName, Context.ContentDatabase.GetItem(itemId, LanguageManager.GetLanguage(language)).Versions.GetLatestVersion().Version.ToString());
     }
     catch (Exception exception)
     {
         Log.Audit("Trying to access an item that does exist from the recently opened tabs", exception);
     }
 }
开发者ID:katebutenko,项目名称:Sitecore-Item-Buckets-6.6-NET4,代码行数:17,代码来源:AddTab.cs

示例4: ReplaceMediaUrl

        /// <summary>
        /// Rewrites media urls to point to CDN hostname and dehydrates querystring into filename
        /// </summary>
        /// <param name="inputUrl">/path/to/file.ext?a=1&b=2</param>
        /// <returns>http://cdnHostname/path/to/file!cf!a=1!b=2.ext</returns>
        public virtual string ReplaceMediaUrl(string inputUrl, string cdnHostname)
        {
            //string versionKey = inputUrl + "_v";
            //string updatedKey = inputUrl + "_d";
            string cachedKey = string.Concat(WebUtil.GetScheme(), inputUrl);
            try
            {

                string cachedUrl = _cache.GetUrl(cachedKey);

                if (!string.IsNullOrEmpty(cachedUrl))
                {
                    return cachedUrl;
                }

                // ignore fully qualified urls or data:
                if (WebUtil.IsExternalUrl(inputUrl) || inputUrl.StartsWith("data:") || inputUrl.StartsWith("//"))
                    return inputUrl;

                UrlString url = new UrlString(WebUtil.NormalizeUrl(inputUrl));
                UrlString originalUrl = new UrlString(WebUtil.NormalizeUrl(inputUrl));

                //  if the stoptoken ex. ?nfc=1  is non-empty, don't replace this url
                if (!string.IsNullOrEmpty(url[this.StopToken]))
                {
                    url.Remove(this.StopToken);
                }
                else
                {

                    if (!string.IsNullOrEmpty(cdnHostname))
                        url.HostName = cdnHostname;  // insert CDN hostname

                    if (CDNSettings.MatchProtocol)
                        url.Protocol = WebUtil.GetScheme();

                    url.Path = StringUtil.EnsurePrefix('/', url.Path);  //ensure first "/" before ~/media


                    if (CDNSettings.FilenameVersioningEnabled)
                    {
                        // if this is a media library request
                        if (inputUrl.Contains(Settings.Media.MediaLinkPrefix))
                        {
                            string version = url["vs"] ?? string.Empty;
                            string updated = string.Empty;


                            // get sitecore path of media item
                            string mediaItemPath = GetMediaItemPath(url.Path);
                            if (!string.IsNullOrEmpty(mediaItemPath) && Sitecore.Context.Database != null)
                            {
                                Item mediaItem = null;
                                if (!string.IsNullOrEmpty(version))
                                {
                                    mediaItem = Sitecore.Context.Database.GetItem(mediaItemPath, Sitecore.Context.Language, Sitecore.Data.Version.Parse(version));
                                }
                                else
                                {
                                    mediaItem = Sitecore.Context.Database.SelectSingleItem(mediaItemPath);
                                }

                                if (mediaItem == null)
                                {
                                    // no change to url
                                    url = originalUrl;
                                }
                                else
                                {
                                    // do not replace url if media item isn't public or requires Analytics processing
                                    // keep local url for this case
                                    if (!this.IsMediaPubliclyAccessible(mediaItem) || IsMediaAnalyticsTracked(mediaItem))
                                    {
                                        // no change to url
                                        url = originalUrl;
                                    }
                                    else
                                    {
                                        version = mediaItem.Version.Number.ToString();
                                        updated = DateUtil.ToIsoDate(mediaItem.Statistics.Updated);
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(version))
                            {
                                // append version number qs
                                url.Add("vs", version);
                            }
                            if (!string.IsNullOrEmpty(updated))
                            {
                                // append  timestamp qs
                                url.Add("d", updated);
                            }
                        }
//.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:SitecoreCDN,代码行数:101,代码来源:CDNProvider.cs

示例5: AddLatestVersionToUrlString

 /// <summary>
 /// Overide Sitecore choosing which version to open and get the latest instead
 /// </summary>
 /// <returns>Void</returns>
 private static void AddLatestVersionToUrlString(CommandContext context, UrlString urlString)
 {
     urlString.Remove("vs");
     urlString.Add("vs", Context.ContentDatabase.GetItem(context.Parameters[0]).Versions.GetLatestVersion().
                             Version.ToString());
 }
开发者ID:udt1106,项目名称:Sitecore-Item-Buckets,代码行数:10,代码来源:AddSlientTab.cs


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