private bool BuildRootPageUrl(IPage rootPage, CultureInfo cultureInfo, UrlSpace urlSpace, StringBuilder result) { var bindings = GetHostnameBindings(); bool knownHostname = urlSpace.Hostname != null && bindings.Any(b => b.Hostname == urlSpace.Hostname); IHostnameBinding hostnameBinding = null; // Searching for a hostname binding matching either the root page, or current hostname/UrlSpace if (!urlSpace.ForceRelativeUrls && knownHostname) { Guid pageId = rootPage.Id; string host = urlSpace.Hostname; string cultureName = cultureInfo.Name; hostnameBinding = bindings.FirstOrDefault(b => b.HomePageId == pageId && b.Hostname == host && b.Culture == cultureName) ?? bindings.FirstOrDefault(b => b.HomePageId == pageId && b.Culture == cultureName) ?? bindings.FirstOrDefault(b => b.HomePageId == pageId && b.Hostname == host) ?? bindings.FirstOrDefault(b => b.HomePageId == pageId); if (hostnameBinding != null) { if (hostnameBinding.Hostname != urlSpace.Hostname) { result.AppendFormat("http{0}://", hostnameBinding.EnforceHttps ? "s" : "") .Append(hostnameBinding.Hostname); } } else { hostnameBinding = bindings.FirstOrDefault(b => b.Hostname == urlSpace.Hostname); } } result.Append(UrlUtils.PublicRootPath); string cultureUrlMapping = DataLocalizationFacade.GetUrlMappingName(cultureInfo); if (cultureUrlMapping != string.Empty && (hostnameBinding == null || hostnameBinding.IncludeCultureInUrl || hostnameBinding.Culture != cultureInfo.Name)) { result.Append("/").Append(cultureUrlMapping); } AppendSlash(result); if (rootPage.UrlTitle != string.Empty && (hostnameBinding == null || hostnameBinding.IncludeHomePageInUrl || hostnameBinding.HomePageId != rootPage.Id)) { result.Append(rootPage.UrlTitle); } return(true); }
private void WriteSiteMapList(IEnumerable <CompositeC1SiteMapNode> rootNodes) { _writer.WriteStartElement("sitemapindex", _ns); List <IHostnameBinding> bindings; using (var data = new DataConnection()) { bindings = data.Get <IHostnameBinding>().ToList(); } foreach (var node in rootNodes) { string urlTitle = null; using (new DataScope(PublicationScope.Published, node.Culture)) { IPage page = PageManager.GetPageById(node.PageNode.Id); if (page != null) { urlTitle = page.UrlTitle; } } IHostnameBinding binding = FindMatchingBinding(node, bindings); _writer.WriteStartElement("sitemap"); var uri = _context.Request.Url; _writer.WriteStartElement("loc"); string hostnameUrl; if (binding == null || MatchHostname(binding)) { hostnameUrl = "{0}://{1}{2}".FormatWith( uri.Scheme, uri.Host, uri.IsDefaultPort ? string.Empty : ":" + uri.Port); } else { hostnameUrl = "http://" + binding.Hostname; } _writer.WriteString(hostnameUrl + "{0}/{1}{2}/sitemap.xml".FormatWith( UrlUtils.PublicRootPath, node.Culture, urlTitle.IsNullOrEmpty() ? string.Empty : "/" + urlTitle)); _writer.WriteEndElement(); _writer.WriteEndElement(); } _writer.WriteEndElement(); }
static void SetCultureByHostname() { IHostnameBinding hostnameBinding = HostnameBindingsFacade.GetBindingForCurrentRequest(); if (hostnameBinding != null && !hostnameBinding.Culture.IsNullOrEmpty()) { var cultureInfo = new CultureInfo(hostnameBinding.Culture); var thread = System.Threading.Thread.CurrentThread; thread.CurrentCulture = cultureInfo; thread.CurrentUICulture = cultureInfo; } }
static void SetCultureByHostname(IHostnameBinding hostnameBinding) { if ((hostnameBinding?.Culture).IsNullOrEmpty()) { return; } var cultureInfo = new CultureInfo(hostnameBinding.Culture); var thread = System.Threading.Thread.CurrentThread; thread.CurrentCulture = cultureInfo; thread.CurrentUICulture = cultureInfo; }
private bool MatchHostname(IHostnameBinding binding) { var host = _requestUrl.Host; if (binding.Hostname == host) { return(true); } return(binding.Aliases .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Any(alias => alias == host)); }
private string GetRootPageBaseUrl(Guid pageId, CultureInfo cultureInfo, out IHostnameBinding appliedHostnameBinding) { // TODO: merge with DefaultPageUrlProvider logic string cultureUrlMapping = DataLocalizationFacade.GetUrlMappingName(cultureInfo); if (!_forceRelativeUrls && _hostnameBindings.Any()) { IHostnameBinding match = _hostnameBindings.FirstOrDefault(b => b.HomePageId == pageId && b.Culture == cultureInfo.Name); if (match == null) { match = _hostnameBindings.FirstOrDefault(b => b.HomePageId == pageId); } if (match != null) { string result = string.Empty; if (match.Hostname != _urlSpace.Hostname) { result = "http://" + match.Hostname; } result += UrlUtils.PublicRootPath; if (match.IncludeCultureInUrl || match.Culture != cultureInfo.Name) { if (cultureUrlMapping != string.Empty) { result += "/" + cultureUrlMapping; } } appliedHostnameBinding = match; return(result); } } appliedHostnameBinding = _hostnameBinding; if (cultureUrlMapping != "" && (appliedHostnameBinding == null || appliedHostnameBinding.IncludeCultureInUrl || appliedHostnameBinding.Culture != cultureInfo.Name)) { return(UrlUtils.PublicRootPath + "/" + cultureUrlMapping); } return(UrlUtils.PublicRootPath); }
public PageUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace) { _publicationScope = publicationScope; _localizationScope = localizationScope; var localeMappedName = DataLocalizationFacade.GetUrlMappingName(localizationScope) ?? string.Empty; _forceRelativeUrls = urlSpace != null && urlSpace.ForceRelativeUrls; if (!_forceRelativeUrls && urlSpace != null && urlSpace.Hostname != null) { List <IHostnameBinding> hostnameBindings = DataFacade.GetData <IHostnameBinding>().ToList(); _hostnameBinding = hostnameBindings.FirstOrDefault(b => b.Hostname == urlSpace.Hostname); bool knownHostname = _hostnameBinding != null; if (knownHostname) { _hostnameBindings = hostnameBindings; _urlSpace = urlSpace; } } if (_hostnameBinding != null && !_hostnameBinding.IncludeCultureInUrl && _hostnameBinding.Culture == localizationScope.Name) { _friendlyUrlPrefix = UrlUtils.PublicRootPath; if (!localeMappedName.IsNullOrEmpty()) { _friendlyUrlPrefixWithLanguageCode = UrlUtils.PublicRootPath + "/" + localeMappedName; } } else { _friendlyUrlPrefix = UrlUtils.PublicRootPath + (localeMappedName.IsNullOrEmpty() ? string.Empty : "/" + localeMappedName); } UrlSuffix = DataFacade.GetData <IUrlConfiguration>().Select(c => c.PageUrlSuffix).FirstOrDefault() ?? string.Empty; }
public PageUrlBuilder(PublicationScope publicationScope, CultureInfo localizationScope, UrlSpace urlSpace) { _publicationScope = publicationScope; _localizationScope = localizationScope; var localeMappedName = DataLocalizationFacade.GetUrlMappingName(localizationScope) ?? string.Empty; _forceRelativeUrls = urlSpace != null && urlSpace.ForceRelativeUrls; if (!_forceRelativeUrls && urlSpace != null && urlSpace.Hostname != null) { List<IHostnameBinding> hostnameBindings = DataFacade.GetData<IHostnameBinding>().ToList(); _hostnameBinding = hostnameBindings.FirstOrDefault(b => b.Hostname == urlSpace.Hostname); bool knownHostname = _hostnameBinding != null; if(knownHostname) { _hostnameBindings = hostnameBindings; _urlSpace = urlSpace; } } if(_hostnameBinding != null && !_hostnameBinding.IncludeCultureInUrl && _hostnameBinding.Culture == localizationScope.Name) { _friendlyUrlPrefix = UrlUtils.PublicRootPath; if (!localeMappedName.IsNullOrEmpty()) { _friendlyUrlPrefixWithLanguageCode = UrlUtils.PublicRootPath + "/" + localeMappedName; } } else { _friendlyUrlPrefix = UrlUtils.PublicRootPath + (localeMappedName.IsNullOrEmpty() ? string.Empty : "/" + localeMappedName); } UrlSuffix = DataFacade.GetData<IUrlConfiguration>().Select(c => c.PageUrlSuffix).FirstOrDefault() ?? string.Empty; }
CultureInfo GetCultureInfo(string requestPath, IHostnameBinding hostnameBinding, out string pathWithoutLanguageAndAppRoot) { int startIndex = requestPath.IndexOf('/', UrlUtils.PublicRootPath.Length) + 1; if (startIndex > 0 && requestPath.Length > startIndex) { int endIndex = requestPath.IndexOf('/', startIndex + 1) - 1; if (endIndex < 0) { endIndex = requestPath.Length - 1; } if (endIndex > startIndex) { string urlMappingName = requestPath.Substring(startIndex, endIndex - startIndex + 1); if (DataLocalizationFacade.UrlMappingNames.Any(um => String.Equals(um, urlMappingName, StringComparison.OrdinalIgnoreCase))) { CultureInfo cultureInfo = DataLocalizationFacade.GetCultureInfoByUrlMappingName(urlMappingName); bool exists = DataLocalizationFacade.ActiveLocalizationNames.Contains(cultureInfo.Name); if (exists) { pathWithoutLanguageAndAppRoot = requestPath.Substring(endIndex + 1); return(cultureInfo); } // Culture is inactive pathWithoutLanguageAndAppRoot = null; return(null); } } } pathWithoutLanguageAndAppRoot = requestPath.Substring(UrlUtils.PublicRootPath.Length); if (hostnameBinding != null && !hostnameBinding.IncludeCultureInUrl) { return(new CultureInfo(hostnameBinding.Culture)); } return(DataLocalizationFacade.DefaultUrlMappingCulture); }
void context_BeginRequest(object sender, EventArgs e) { if (!SystemSetupFacade.IsSystemFirstTimeInitialized) { return; } ThreadDataManager.InitializeThroughHttpContext(); var httpContext = (sender as HttpApplication).Context; if (CheckForHostnameAliasRedirect(httpContext)) { return; } IHostnameBinding hostnameBinding = HostnameBindingsFacade.GetBindingForCurrentRequest(); if (hostnameBinding != null && hostnameBinding.EnforceHttps && !httpContext.Request.IsSecureConnection) { RedirectToHttps(httpContext); return; } if (HandleMediaRequest(httpContext)) { return; } SetCultureByHostname(hostnameBinding); PrettifyPublicMarkup(httpContext); HandleRootRequestInClassicMode(httpContext); }
private string GetRootPageBaseUrl(Guid pageId, CultureInfo cultureInfo, out IHostnameBinding appliedHostnameBinding) { // TODO: merge with DefaultPageUrlProvider logic string cultureUrlMapping = DataLocalizationFacade.GetUrlMappingName(cultureInfo); if (!_forceRelativeUrls && _hostnameBindings.Any()) { IHostnameBinding match = _hostnameBindings.FirstOrDefault(b => b.HomePageId == pageId && b.Culture == cultureInfo.Name); if(match == null) { match = _hostnameBindings.FirstOrDefault(b => b.HomePageId == pageId); } if(match != null) { string result = string.Empty; if (match.Hostname != _urlSpace.Hostname) { result = "http://" + match.Hostname; } result += UrlUtils.PublicRootPath; if (match.IncludeCultureInUrl || match.Culture != cultureInfo.Name) { if (cultureUrlMapping != string.Empty) { result += "/" + cultureUrlMapping; } } appliedHostnameBinding = match; return result; } } appliedHostnameBinding = _hostnameBinding; if (cultureUrlMapping != "" && (appliedHostnameBinding == null || appliedHostnameBinding.IncludeCultureInUrl || appliedHostnameBinding.Culture != cultureInfo.Name)) { return UrlUtils.PublicRootPath + "/" + cultureUrlMapping; } return UrlUtils.PublicRootPath; }
public PageUrlSet BuildUrlSet(IPage page, Guid parentPageId) { Verify.ArgumentNotNull(page, "page"); Verify.ArgumentCondition(page.DataSourceId.PublicationScope == _publicationScope, "page", "Page belongs to a wrong publication scope"); Verify.ArgumentCondition(page.DataSourceId.LocaleScope.Name == _localizationScope.Name, "page", "Page belongs to a wrong localization scope"); DataScopeIdentifier dataScopeIdentifier = page.DataSourceId.DataScopeIdentifier; CultureInfo cultureInfo = page.DataSourceId.LocaleScope; string parentPath; IHostnameBinding appliedHostnameBinding = null; // Checking if it is a root-level page if (parentPageId == Guid.Empty) { parentPath = GetRootPageBaseUrl(page.Id, cultureInfo, out appliedHostnameBinding); } else { Verify.That(_folderPaths.ContainsKey(parentPageId), "Method BuildUrlInternal() should be called for parent page before running for childildren, so 'urlBuildingCache' parameter will contains parent pages data."); parentPath = _folderPaths[parentPageId]; } // Building folderPath & lookup url string lookupUrl, folderPath; if (page.UrlTitle == string.Empty || (appliedHostnameBinding != null && !appliedHostnameBinding.IncludeHomePageInUrl && appliedHostnameBinding.HomePageId == page.Id)) { // Extensionless root url lookupUrl = folderPath = (parentPath == "" ? "/" : parentPath); } else { string parentPathWithSlash = parentPath + (parentPath.EndsWith("/") ? "" : "/"); string urlTitle = page.UrlTitle; #if URLDEBUG urlTitle = UrlFormattersPluginFacade.FormatUrl(urlTitle, true); #endif folderPath = parentPathWithSlash + urlTitle; lookupUrl = folderPath + UrlSuffix; } _folderPaths.Add(page.Id, folderPath); string lookupUrlLowerCased = lookupUrl.ToLowerInvariant(); if (UrlToIdLookupLowerCased.ContainsKey(lookupUrlLowerCased)) { if (!_knownNotUniqueUrls.Contains(lookupUrlLowerCased)) { lock (_knownNotUniqueUrls) { _knownNotUniqueUrls.Add(lookupUrlLowerCased); } Log.LogError(LogTitle, "Multiple pages share the same path '{0}'. Page ID: '{1}'. Duplicates are ignored.".FormatWith(lookupUrlLowerCased, page.Id)); } return(null); } UrlToIdLookupLowerCased.Add(lookupUrlLowerCased, page.Id); UrlToIdLookup.Add(lookupUrl, page.Id); IdToUrlLookup.Add(page.Id, lookupUrl); // Building redirect folder path & url string redirectParentPath = (parentPageId == Guid.Empty) ? GetRedirectBaseUrl(cultureInfo) : _redirectFolderPaths[parentPageId]; if (redirectParentPath != null) { string redirectLookupUrl; string redirectFolderPath; if (!page.UrlTitle.IsNullOrEmpty()) { string parentPathWithTrailingSlash = redirectParentPath + (redirectParentPath.EndsWith("/") ? "" : "/"); redirectFolderPath = parentPathWithTrailingSlash + page.UrlTitle; redirectLookupUrl = redirectFolderPath + UrlSuffix; } else { redirectLookupUrl = redirectFolderPath = redirectParentPath; } if (redirectLookupUrl != lookupUrl || UrlSuffix == string.Empty) { _redirectFolderPaths.Add(page.Id, redirectFolderPath); string redirectLookupUrlLowerCased = redirectLookupUrl.ToLowerInvariant(); if (redirectLookupUrlLowerCased != lookupUrlLowerCased) { if (!RedirectUrlToIdLookupLowerCased.ContainsKey(redirectLookupUrlLowerCased)) { RedirectUrlToIdLookupLowerCased.Add(redirectLookupUrlLowerCased, page.Id); } } if (UrlSuffix == string.Empty) { string aspxExtensionRedirectUrl = redirectLookupUrlLowerCased + ".aspx"; if (!RedirectUrlToIdLookupLowerCased.ContainsKey(aspxExtensionRedirectUrl)) { RedirectUrlToIdLookupLowerCased.Add(aspxExtensionRedirectUrl, page.Id); } } } } string url = lookupUrl; if (_forceRelativeUrls) { url = UrlUtils.Combine(url, DefaultPageUrlProvider.UrlMarker_RelativeUrl); } if (dataScopeIdentifier.Name == DataScopeIdentifier.AdministratedName) { url = UrlUtils.Combine(url, DefaultPageUrlProvider.UrlMarker_Unpublished); } var pageUrls = new PageUrlSet { PublicUrl = url }; if (!string.IsNullOrEmpty(page.FriendlyUrl)) { string friendlyUrl = _friendlyUrlPrefix + MakeRelativeUrl(page.FriendlyUrl); string lowerCasedFriendlyUrl = friendlyUrl.ToLowerInvariant(); if (!FriendlyUrlToIdLookup.ContainsKey(lowerCasedFriendlyUrl)) { pageUrls.FriendlyUrl = friendlyUrl; FriendlyUrlToIdLookup.Add(lowerCasedFriendlyUrl, page.Id); } if (_friendlyUrlPrefixWithLanguageCode != null) { string alternativeFriendlyUrl = (_friendlyUrlPrefixWithLanguageCode + MakeRelativeUrl(page.FriendlyUrl)).ToLowerInvariant(); if (!FriendlyUrlToIdLookup.ContainsKey(alternativeFriendlyUrl)) { FriendlyUrlToIdLookup.Add(alternativeFriendlyUrl, page.Id); } } } return(pageUrls); }
private static Guid?TryGetPageByUrlTitlePath(string pagePath, bool pathInfoExtracted, IHostnameBinding hostnameBinding, ref string pathInfo) { string[] pageUrlTitles = pagePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (pageUrlTitles.Length == 0) { if (hostnameBinding != null) { if (!hostnameBinding.IncludeHomePageInUrl) { return(hostnameBinding.HomePageId); } IPage rootPage = PageManager.GetPageById(hostnameBinding.HomePageId); if (rootPage != null && string.IsNullOrEmpty(rootPage.UrlTitle)) { return(hostnameBinding.HomePageId); } return(null); } } IEnumerable <IPage> rootPages = GetChildPages(Guid.Empty); if (pageUrlTitles.Length == 0) { return(rootPages.Where(p => string.IsNullOrEmpty(p.UrlTitle)).Select(p => p.Id).FirstOrDefault()); } string firstUrlTitle = pageUrlTitles[0]; Guid?firstPageId = null; if (hostnameBinding != null) { IPage rootPage = PageManager.GetPageById(hostnameBinding.HomePageId); bool rootPageIsOmmited = rootPage != null && !hostnameBinding.IncludeHomePageInUrl || string.IsNullOrEmpty(rootPage.UrlTitle); if (rootPageIsOmmited) { firstPageId = FindMatchingPage(rootPage.Id, firstUrlTitle); } } if (firstPageId == null) { IPage defaultRootPage = rootPages.FirstOrDefault(p => string.IsNullOrEmpty(p.UrlTitle)); if (defaultRootPage != null) { firstPageId = FindMatchingPage(defaultRootPage.Id, firstUrlTitle); } if (firstPageId == null) { // Searching the first pageId among root pages firstPageId = FindMatchingPage(Guid.Empty, firstUrlTitle); } if (firstPageId == null) { return(null); } } Guid currentPageId = firstPageId.Value; if (pageUrlTitles.Length == 1) { return(currentPageId); } for (int i = 1; i < pageUrlTitles.Length; i++) { Guid?nextPage = FindMatchingPage(currentPageId, pageUrlTitles[i]); if (nextPage == null) { if (pathInfoExtracted) { return(null); } pathInfo = "/" + string.Join("/", pageUrlTitles.Skip(i)); return(currentPageId); } currentPageId = nextPage.Value; } return(currentPageId); }
private PageUrlData ParsePagePath(string pagePath, PublicationScope publicationScope, CultureInfo locale, IHostnameBinding hostnameBinding) { // Parshing what's left: // [/Path to a page][UrlSuffix]{/PathInfo} string pathInfo = null; bool canBePublicUrl = true; bool pathInfoExctracted = false; if (!string.IsNullOrEmpty(UrlSuffix)) { string urlSuffixPlusSlash = UrlSuffix + "/"; int suffixOffset = pagePath.IndexOf(urlSuffixPlusSlash, StringComparison.OrdinalIgnoreCase); if (suffixOffset > 0) { pathInfo = pagePath.Substring(suffixOffset + urlSuffixPlusSlash.Length); pagePath = pagePath.Substring(0, suffixOffset); pathInfoExctracted = true; } else if (pagePath.EndsWith(UrlSuffix, StringComparison.OrdinalIgnoreCase)) { pagePath = pagePath.Substring(0, pagePath.Length - UrlSuffix.Length); pathInfoExctracted = true; } else { canBePublicUrl = pagePath == "/"; // Only root page may not have a UrlSuffix } } if (canBePublicUrl) { Guid?pageId = TryGetPageByUrlTitlePath(pagePath, pathInfoExctracted, hostnameBinding, ref pathInfo); if (pageId != null && pageId != Guid.Empty) { return(new PageUrlData(pageId.Value, publicationScope, locale) { PathInfo = pathInfo }); } } return(null); }
public PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind) { if (IsInternalUrl(relativeUrl)) { return(ParseInternalUrl(relativeUrl, out urlKind)); } var urlBuilder = new UrlBuilder(relativeUrl); // Structure of a public url: // http://<hostname>[/ApplicationVirtualPath]{/languageCode}[/Path to a page][/c1mode(unpublished)][/c1mode(relative)][UrlSuffix]{/PathInfo} string filePathAndPathInfo = HttpUtility.UrlDecode(urlBuilder.FullPath); filePathAndPathInfo = RemoveUrlMarkers(filePathAndPathInfo, urlSpace); string pathWithoutLanguageCode; IHostnameBinding hostnameBinding = urlSpace.ForceRelativeUrls ? null : GetHostnameBindings().FirstOrDefault(b => b.Hostname == urlSpace.Hostname); CultureInfo locale = GetCultureInfo(filePathAndPathInfo, hostnameBinding, out pathWithoutLanguageCode); if (locale == null) { urlKind = UrlKind.Undefined; return(null); } var publicationScope = PublicationScope.Published; if (filePathAndPathInfo.Contains(UrlMarker_Unpublished)) { publicationScope = PublicationScope.Unpublished; pathWithoutLanguageCode = pathWithoutLanguageCode.Replace(UrlMarker_Unpublished, string.Empty); if (pathWithoutLanguageCode == string.Empty) { pathWithoutLanguageCode = "/"; } } using (new DataScope(publicationScope, locale)) { bool isObsolete = false; string pathToResolve = pathWithoutLanguageCode; // Supporting obsolete "*.aspx" urls if (!string.Equals(UrlSuffix, ".aspx", StringComparison.OrdinalIgnoreCase) && (pathToResolve.Contains(".aspx/") || pathToResolve.EndsWith(".aspx"))) { pathToResolve = pathToResolve.Replace(".aspx", UrlSuffix); isObsolete = true; } PageUrlData data = ParsePagePath(pathToResolve, publicationScope, locale, hostnameBinding); if (data != null) { urlKind = !isObsolete ? UrlKind.Public : UrlKind.Redirect; data.QueryParameters = urlBuilder.GetQueryParameters(); return(data); } Guid friendlyUrlPageId = ParseFriendlyUrlPath(pathWithoutLanguageCode); if (friendlyUrlPageId != Guid.Empty) { urlKind = UrlKind.Friendly; return(new PageUrlData(friendlyUrlPageId, publicationScope, locale) { QueryParameters = urlBuilder.GetQueryParameters() }); } } urlKind = UrlKind.Undefined; return(null); }
private bool MatchHostname(IHostnameBinding binding) { var host = _requestUrl.Host; if (binding.Hostname == host) { return true; } return binding.Aliases .Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) .Any(alias => alias == host); }
CultureInfo GetCultureInfo(string requestPath, IHostnameBinding hostnameBinding, out string pathWithoutLanguageAndAppRoot) { int startIndex = requestPath.IndexOf('/', UrlUtils.PublicRootPath.Length) + 1; if (startIndex > 0 && requestPath.Length > startIndex) { int endIndex = requestPath.IndexOf('/', startIndex + 1) - 1; if(endIndex < 0) { endIndex = requestPath.Length - 1; } if (endIndex > startIndex) { string urlMappingName = requestPath.Substring(startIndex, endIndex - startIndex + 1); if (DataLocalizationFacade.UrlMappingNames.Any(um => String.Equals(um, urlMappingName, StringComparison.OrdinalIgnoreCase))) { CultureInfo cultureInfo = DataLocalizationFacade.GetCultureInfoByUrlMappingName(urlMappingName); bool exists = DataLocalizationFacade.ActiveLocalizationNames.Contains(cultureInfo.Name); if (exists) { pathWithoutLanguageAndAppRoot = requestPath.Substring(endIndex + 1); return cultureInfo; } // Culture is inactive pathWithoutLanguageAndAppRoot = null; return null; } } } pathWithoutLanguageAndAppRoot = requestPath.Substring(UrlUtils.PublicRootPath.Length); if (hostnameBinding != null && !hostnameBinding.IncludeCultureInUrl) { return new CultureInfo(hostnameBinding.Culture); } return DataLocalizationFacade.DefaultUrlMappingCulture; }
private static Guid? TryGetPageByUrlTitlePath(string pagePath, bool pathInfoExtracted, IHostnameBinding hostnameBinding, ref string pathInfo) { string[] pageUrlTitles = pagePath.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); if (pageUrlTitles.Length == 0) { if (hostnameBinding != null) { if (!hostnameBinding.IncludeHomePageInUrl) return hostnameBinding.HomePageId; IPage rootPage = PageManager.GetPageById(hostnameBinding.HomePageId); if (rootPage != null && string.IsNullOrEmpty(rootPage.UrlTitle)) { return hostnameBinding.HomePageId; } return null; } } IEnumerable<IPage> rootPages = GetChildPages(Guid.Empty); if (pageUrlTitles.Length == 0) { return rootPages.Where(p => string.IsNullOrEmpty(p.UrlTitle)).Select(p => p.Id).FirstOrDefault(); } string firstUrlTitle = pageUrlTitles[0]; Guid? firstPageId = null; if (hostnameBinding != null) { IPage rootPage = PageManager.GetPageById(hostnameBinding.HomePageId); bool rootPageIsOmmited = rootPage != null && !hostnameBinding.IncludeHomePageInUrl || string.IsNullOrEmpty(rootPage.UrlTitle); if (rootPageIsOmmited) { firstPageId = FindMatchingPage(rootPage.Id, firstUrlTitle); } } if (firstPageId == null) { IPage defaultRootPage = rootPages.FirstOrDefault(p => string.IsNullOrEmpty(p.UrlTitle)); if (defaultRootPage != null) { firstPageId = FindMatchingPage(defaultRootPage.Id, firstUrlTitle); } if (firstPageId == null) { // Searching the first pageId among root pages firstPageId = FindMatchingPage(Guid.Empty, firstUrlTitle); } if (firstPageId == null) return null; } Guid currentPageId = firstPageId.Value; if (pageUrlTitles.Length == 1) return currentPageId; for (int i = 1; i < pageUrlTitles.Length; i++) { Guid? nextPage = FindMatchingPage(currentPageId, pageUrlTitles[i]); if (nextPage == null) { if (pathInfoExtracted) return null; pathInfo = "/" + string.Join("/", pageUrlTitles.Skip(i)); return currentPageId; } currentPageId = nextPage.Value; } return currentPageId; }
private PageUrlData ParsePagePath(string pagePath, PublicationScope publicationScope, CultureInfo locale, IHostnameBinding hostnameBinding) { // Parshing what's left: // [/Path to a page][UrlSuffix]{/PathInfo} string pathInfo = null; bool canBePublicUrl = true; bool pathInfoExctracted = false; if (!string.IsNullOrEmpty(UrlSuffix)) { string urlSuffixPlusSlash = UrlSuffix + "/"; int suffixOffset = pagePath.IndexOf(urlSuffixPlusSlash, StringComparison.OrdinalIgnoreCase); if (suffixOffset > 0) { pathInfo = pagePath.Substring(suffixOffset + UrlSuffix.Length); pagePath = pagePath.Substring(0, suffixOffset); pathInfoExctracted = true; } else if (pagePath.EndsWith(UrlSuffix, StringComparison.OrdinalIgnoreCase)) { pagePath = pagePath.Substring(0, pagePath.Length - UrlSuffix.Length); pathInfoExctracted = true; } else { canBePublicUrl = pagePath == "/"; // Only root page may not have a UrlSuffix } } if (canBePublicUrl) { Guid? pageId = TryGetPageByUrlTitlePath(pagePath, pathInfoExctracted, hostnameBinding, ref pathInfo); if (pageId != null && pageId != Guid.Empty) { return new PageUrlData(pageId.Value, publicationScope, locale) { PathInfo = pathInfo}; } } return null; }