本文整理汇总了C#中ContentItem.SelectLanguage方法的典型用法代码示例。如果您正苦于以下问题:C# ContentItem.SelectLanguage方法的具体用法?C# ContentItem.SelectLanguage怎么用?C# ContentItem.SelectLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentItem
的用法示例。
在下文中一共展示了ContentItem.SelectLanguage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNormalizedPageUrl
private string GetNormalizedPageUrl(ContentItem pageToNormalize)
{
if (pageToNormalize == null) return null;
if (pageToNormalize is LanguageRoot
|| pageToNormalize is StartPage
|| pageToNormalize is LanguageIntersection)
return GetRootPath(pageToNormalize);
string baseUrl = null;
var context = Context.Current.RequestContext;
// should use DI - NOT DependencyResolver.Current.Get<IWebContext>();
var currentPage = context.CurrentPage;
if (currentPage != null)
{
// Attempt to take the baseUrl from the current page.
var languageRoot = CmsFinder.FindLanguageRootOf(currentPage);
if (languageRoot != null)
baseUrl = languageRoot.Url;
}
if (string.IsNullOrEmpty(baseUrl))
{
// Attempt to take the baseUrl from the pageToNormalize
var languageRoot = CmsFinder.FindLanguageRootOf(pageToNormalize);
if (languageRoot != null)
baseUrl = languageRoot.Url;
}
if (string.IsNullOrEmpty(baseUrl))
{
// Attempt to take the baseUrl from the URL
var pageUrlFragments = context.Url.ApplicationRelativePath.Split('/');
// verify that the first two fragments are the siteId and language
if (pageUrlFragments.Length >= 2)
{
var fragment1 = pageUrlFragments[0];
var fragment2 = pageUrlFragments[1];
var startPage =
CmsFinder.FindLanguageIntersection()
.GetChildren<StartPage>()
.FirstOrDefault(
sp => sp.SiteID.Equals(fragment1, StringComparison.InvariantCultureIgnoreCase));
if (startPage != null)
{
var languageRoot =
startPage.GetChildren<LanguageRoot>()
.FirstOrDefault(
lr =>
lr.LanguageCode.Equals(fragment2, StringComparison.InvariantCultureIgnoreCase));
if (languageRoot != null)
baseUrl = string.Concat(pageUrlFragments[0], "/", pageUrlFragments[1]);
}
}
}
if (string.IsNullOrEmpty(baseUrl))
{
// Try to use websession.
if (WebSession.IsInitialized && !string.IsNullOrEmpty(WebSession.Current.SiteId) && !string.IsNullOrEmpty(WebSession.Current.CultureCode))
baseUrl = string.Concat(WebSession.Current.SiteId, "/", WebSession.Current.CultureCode);
}
if (string.IsNullOrEmpty(baseUrl))
{
// Try to get the baseUrl based on the user's language.
var language = pageToNormalize.SelectLanguage(HttpContext.Current.Request.UserLanguages);
baseUrl = language.Url;
}
if (string.IsNullOrEmpty(baseUrl)) // We are unable to form a valid base Url
return null;
// build page URL from the page and it's ancestors.
string pageUrl = GetRelativePathForItem(pageToNormalize);
var relativeUrl = Url.Combine(baseUrl.ToLowerInvariant(), pageUrl);
relativeUrl = Url.Combine(context.HttpContext.Request.ApplicationPath, relativeUrl);
return Url.Combine(context.Url.HostUrl, relativeUrl);
}