本文整理汇总了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());
}
示例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))
//.........这里部分代码省略.........
示例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);
}
}
示例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);
}
}
//.........这里部分代码省略.........
示例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());
}