コード例 #1
0
        /// <summary>
        /// Looks for wildcard domains in the path and updates <c>Culture</c> accordingly.
        /// </summary>
        internal void HandleWildcardDomains()
        {
            const string tracePrefix = "HandleWildcardDomains: ";

            if (!_pcr.HasPublishedContent)
            {
                return;
            }

            var nodePath = _pcr.PublishedContent.Path;

            LogHelper.Debug <PublishedContentRequestEngine>("{0}Path=\"{1}\"", () => tracePrefix, () => nodePath);
            var rootNodeId = _pcr.HasDomain ? _pcr.Domain.RootNodeId : (int?)null;
            var domain     = DomainHelper.FindWildcardDomainInPath(DomainHelper.GetAllDomains(true), nodePath, rootNodeId);

            if (domain != null)
            {
                _pcr.Culture = new CultureInfo(domain.Language.CultureAlias);
                LogHelper.Debug <PublishedContentRequestEngine>("{0}Got domain on node {1}, set culture to \"{2}\".", () => tracePrefix,
                                                                () => domain.RootNodeId, () => _pcr.Culture.Name);
            }
            else
            {
                LogHelper.Debug <PublishedContentRequestEngine>("{0}No match.", () => tracePrefix);
            }
        }
コード例 #2
0
        /// <summary>
        /// Finds the site root (if any) matching the http request, and updates the PublishedContentRequest accordingly.
        /// </summary>
        /// <returns>A value indicating whether a domain was found.</returns>
        internal bool FindDomain()
        {
            const string tracePrefix = "FindDomain: ";

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

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

            // try to find a domain matching the current request
            var domainAndUri = DomainHelper.DomainForUri(DomainHelper.GetAllDomains(false), _pcr.Uri);

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

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

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

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

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

            return(_pcr.Domain != null);
        }