Beispiel #1
0
        Uri DomainUriAtNode(int nodeId, Uri current)
        {
            // be safe
            if (nodeId <= 0)
            {
                return(null);
            }

            // apply filter on domains defined on that node
            var domainAndUri = DomainHelper.DomainMatch(Domain.GetDomainsById(nodeId), current, true);

            return(domainAndUri == null ? null : domainAndUri.Uri);
        }
        /// <summary>
        /// Determines the site root (if any) matching the http request.
        /// </summary>
        /// <returns>A value indicating whether a domain was found.</returns>
        internal bool LookupDomain()
        {
            const string tracePrefix = "LookupDomain: ";

            // note - we are not handling schemes nor ports here.

            LogHelper.Debug <PublishedContentRequest>("{0}Uri=\"{1}\"", () => tracePrefix, () => _publishedContentRequest.Uri);

            // try to find a domain matching the current request
            var domainAndUri = DomainHelper.DomainMatch(Domain.GetDomains(), _umbracoContext.CleanedUmbracoUrl, false);

            // handle domain
            if (domainAndUri != null)
            {
                // matching an existing domain
                LogHelper.Debug <PublishedContentRequest>("{0}Matches domain=\"{1}\", rootId={2}, culture=\"{3}\"",
                                                          () => tracePrefix,
                                                          () => domainAndUri.Domain.Name,
                                                          () => domainAndUri.Domain.RootNodeId,
                                                          () => domainAndUri.Domain.Language.CultureAlias);

                _publishedContentRequest.Domain    = domainAndUri.Domain;
                _publishedContentRequest.DomainUri = domainAndUri.Uri;
                _publishedContentRequest.Culture   = new CultureInfo(domainAndUri.Domain.Language.CultureAlias);

                // canonical? not implemented at the moment
                // if (...)
                // {
                //  this.RedirectUrl = "...";
                //  return true;
                // }
            }
            else
            {
                // not matching any existing domain
                LogHelper.Debug <PublishedContentRequest>("{0}Matches no domain", () => tracePrefix);

                var defaultLanguage = Language.GetAllAsList().FirstOrDefault();
                _publishedContentRequest.Culture = defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.CultureAlias);
            }

            LogHelper.Debug <PublishedContentRequest>("{0}Culture=\"{1}\"", () => tracePrefix, () => _publishedContentRequest.Culture.Name);

            return(_publishedContentRequest.Domain != null);
        }