本文整理汇总了C#中N2.Web.Url.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Url.ToString方法的具体用法?C# Url.ToString怎么用?C# Url.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类N2.Web.Url
的用法示例。
在下文中一共展示了Url.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanConstruct_AbsoluteLocalPath_WithFragment
public void CanConstruct_AbsoluteLocalPath_WithFragment()
{
Url u = new Url("/hello.aspx#somebookmark");
Assert.That(u.Path, Is.EqualTo("/hello.aspx"));
Assert.That(u.Fragment, Is.EqualTo("somebookmark"));
Assert.That(u.ToString(), Is.EqualTo("/hello.aspx#somebookmark"));
}
示例2: CanConstruct_FromHostName
public void CanConstruct_FromHostName()
{
Url u = new Url("http://somesite/");
Assert.That(u.Scheme, Is.EqualTo("http"));
Assert.That(u.Authority, Is.EqualTo("somesite"));
Assert.That(u.ToString(), Is.EqualTo("http://somesite/"));
}
示例3: CanConstruct_AbsoluteLocalPath_WithQuery
public void CanConstruct_AbsoluteLocalPath_WithQuery()
{
Url u = new Url("/hello.aspx?something=someotherthing");
Assert.That(u.Path, Is.EqualTo("/hello.aspx"));
Assert.That(u.Query, Is.EqualTo("something=someotherthing"));
Assert.That(u.ToString(), Is.EqualTo("/hello.aspx?something=someotherthing"));
}
示例4: ResolveUrl
public virtual PathData ResolveUrl(Url url)
{
// simple cache to help with multiple requests for same URL - PoC
if ((lastUrl != null) && (lastUrl.Item1 == url.ToString()))
{
var result = lastUrl.Item2;
lastUrl = null;
return result;
}
try
{
var path = parser.FindPath(url.RemoveDefaultDocument(Url.DefaultDocument).RemoveExtension(observedExtensions));
path.CurrentItem = path.CurrentPage;
if (draftRepository.Versions.TryParseVersion(url[PathData.VersionIndexQueryKey], url["versionKey"], path))
{
lastUrl = new Tuple<string, PathData>(url, path);
return path;
}
string viewPreferenceParameter = url.GetQuery(WebExtensions.ViewPreferenceQueryString);
if (viewPreferenceParameter == WebExtensions.DraftQueryValue && draftRepository.HasDraft(path.CurrentItem))
{
var draft = draftRepository.Versions.GetVersion(path.CurrentPage);
path.TryApplyVersion(draft, url["versionKey"]);
}
lastUrl = new Tuple<string, PathData>(url, path);
return path;
}
catch (Exception ex)
{
errorHandler.Notify(ex);
}
return PathData.Empty;
}
示例5: CanConstruct_AbsoluteLocalPath
public void CanConstruct_AbsoluteLocalPath()
{
Url u = new Url("/hello.aspx");
Assert.That(u.Path, Is.EqualTo("/hello.aspx"));
Assert.That(u.ToString(), Is.EqualTo("/hello.aspx"));
}
示例6: NullUrl
public void NullUrl()
{
Url u = new Url((string)null);
Assert.That(u.Path, Is.EqualTo(""));
Assert.That(u.ToString(), Is.EqualTo(""));
}
示例7: EmptyUrl
public void EmptyUrl()
{
Url u = new Url("");
Assert.That(u.Path, Is.EqualTo(""));
Assert.That(u.ToString(), Is.EqualTo(""));
}
示例8: 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;
}
示例9: UpdatingQueryToNull_ReturnsOtherParameters_WhenUpdatingLast
public void UpdatingQueryToNull_ReturnsOtherParameters_WhenUpdatingLast()
{
Url u = new Url("/hello.aspx?something=someotherthing&query=value&query3=value3");
u = u.SetQueryParameter("query3", null);
Assert.That(u.ToString(), Is.EqualTo("/hello.aspx?something=someotherthing&query=value"));
}
示例10: GetUrlLowerInvariantString
/// <summary>
/// Returns the string of the current url in invariant culture
/// </summary>
/// <param name="url">Url to get the string of</param>
/// <returns>Lowered invariant string of the url passed in</returns>
private string GetUrlLowerInvariantString(Url url)
{
return url.ToString().ToLowerInvariant();
}
示例11: ResolvePath
/// <summary>Finds the content item and the template associated with an url.</summary>
/// <param name="url">The url to the template to locate.</param>
/// <returns>A TemplateData object. If no template was found the object will have empty properties.</returns>
public PathData ResolvePath(Url url)
{
string key = url.ToString().ToLowerInvariant();
PathData data = HttpRuntime.Cache[key] as PathData;
if(data == null)
{
data = inner.ResolvePath(url);
if (!data.IsEmpty() && data.IsCacheable)
{
Debug.WriteLine("Adding " + url + " to cache");
HttpRuntime.Cache.Add(key, data.Detach(), new ContentCacheDependency(persister), Cache.NoAbsoluteExpiration, SlidingExpiration, CacheItemPriority.Normal, null);
}
}
else
{
Debug.WriteLine("Retrieving " + url + " from cache");
data = data.Attach(persister);
data.UpdateParameters(Url.Parse(url).GetQueries());
}
return data;
}
示例12: 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;
}
示例13: GenerateSearchActionLink
public string GenerateSearchActionLink()
{
string ret;
var cacheKey = string.Format("{0} {1} {2}", WebSession.Current.SiteId, WebSession.Current.LanguageCode, "SearchActionLink");
if (!_urlCache.TryGet(cacheKey, out ret))
{
var page = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot<SearchPage>().LastOrDefault();
if (page == 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(page));
ret = url.ToString();
}
AddCache(cacheKey, ret);
}
return ret;
}
示例14: 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;
}
示例15: CanConstruct_HomePath
public void CanConstruct_HomePath()
{
Url u = new Url("/");
Assert.That(u.Path, Is.EqualTo("/"));
Assert.That(u.ToString(), Is.EqualTo("/"));
}