コード例 #1
0
        public static PortalAliasCollection GetPortalAliasLookup()
        {
            var portalAliasCollection = new PortalAliasCollection();
            var aliasController       = new PortalAliasController();

            foreach (var kvp in aliasController.GetPortalAliasesInternal())
            {
                portalAliasCollection.Add(kvp.Key, kvp.Value);
            }

            return(portalAliasCollection);
        }
コード例 #2
0
        /// <inheritdoc/>
        string IPortalAliasService.GetPortalAliasByPortal(int portalId, string portalAlias)
        {
            string retValue        = string.Empty;
            bool   foundAlias      = false;
            var    portalAliasInfo = this.ThisAsInterface.GetPortalAlias(portalAlias, portalId);

            if (portalAliasInfo != null)
            {
                retValue   = portalAliasInfo.HttpAlias;
                foundAlias = true;
            }

            if (!foundAlias)
            {
                // searching from longest to shortest alias ensures that the most specific portal is matched first
                // In some cases this method has been called with "portalaliases" that were not exactly the real portal alias
                // the startswith behaviour is preserved here to support those non-specific uses
                var controller            = new PortalAliasController();
                var portalAliases         = controller.GetPortalAliasesInternal();
                var portalAliasCollection = portalAliases.OrderByDescending(k => k.Key.Length);

                foreach (var currentAlias in portalAliasCollection)
                {
                    // check if the alias key starts with the portal alias value passed in - we use
                    // StartsWith because child portals are redirected to the parent portal domain name
                    // eg. child = 'www.domain.com/child' and parent is 'www.domain.com'
                    // this allows the parent domain name to resolve to the child alias ( the tabid still identifies the child portalid )
                    IPortalAliasInfo currentAliasInfo = currentAlias.Value;
                    string           httpAlias        = currentAliasInfo.HttpAlias.ToLowerInvariant();
                    if (httpAlias.StartsWith(portalAlias.ToLowerInvariant()) && currentAliasInfo.PortalId == portalId)
                    {
                        retValue = currentAliasInfo.HttpAlias;
                        break;
                    }

                    httpAlias = httpAlias.StartsWith("www.") ? httpAlias.Replace("www.", string.Empty) : string.Concat("www.", httpAlias);
                    if (httpAlias.StartsWith(portalAlias.ToLowerInvariant()) && currentAliasInfo.PortalId == portalId)
                    {
                        retValue = currentAliasInfo.HttpAlias;
                        break;
                    }
                }
            }

            return(retValue);
        }
コード例 #3
0
        public static PortalAliasCollection GetPortalAliasLookup()
        {
            var portalAliasCollection = new PortalAliasCollection();
            var aliasController = new PortalAliasController();
            foreach (var kvp in aliasController.GetPortalAliasesInternal())
            {
                portalAliasCollection.Add(kvp.Key, kvp.Value);
            }

            return portalAliasCollection;
        }
コード例 #4
0
        private IPortalAliasInfo GetPortalAliasInternal(string httpAlias)
        {
            string strPortalAlias;

            // try the specified alias first
            IPortalAliasInfo portalAlias = this.GetPortalAliasLookupInternal(httpAlias.ToLowerInvariant());

            // domain.com and www.domain.com should be synonymous
            if (portalAlias == null)
            {
                if (httpAlias.StartsWith("www.", StringComparison.InvariantCultureIgnoreCase))
                {
                    // try alias without the "www." prefix
                    strPortalAlias = httpAlias.Replace("www.", string.Empty);
                }
                else // try the alias with the "www." prefix
                {
                    strPortalAlias = string.Concat("www.", httpAlias);
                }

                // perform the lookup
                portalAlias = this.GetPortalAliasLookupInternal(strPortalAlias.ToLowerInvariant());
            }

            // allow domain wildcards
            if (portalAlias == null)
            {
                // remove the domain prefix ( ie. anything.domain.com = domain.com )
                if (httpAlias.IndexOf(".", StringComparison.Ordinal) != -1)
                {
                    strPortalAlias = httpAlias.Substring(httpAlias.IndexOf(".", StringComparison.Ordinal) + 1);
                }
                else // be sure we have a clean string (without leftovers from preceding 'if' block)
                {
                    strPortalAlias = httpAlias;
                }

                // try an explicit lookup using the wildcard entry ( ie. *.domain.com )
                portalAlias = this.GetPortalAliasLookupInternal("*." + strPortalAlias.ToLowerInvariant()) ??
                              this.GetPortalAliasLookupInternal(strPortalAlias.ToLowerInvariant());

                if (portalAlias == null)
                {
                    // try a lookup using "www." + raw domain
                    portalAlias = this.GetPortalAliasLookupInternal("www." + strPortalAlias.ToLowerInvariant());
                }
            }

            if (portalAlias == null)
            {
                // check if this is a fresh install ( no alias values in collection )
                var controller    = new PortalAliasController();
                var portalAliases = controller.GetPortalAliasesInternal();
                if (portalAliases.Keys.Count == 0 || (portalAliases.Count == 1 && portalAliases.ContainsKey("_default")))
                {
                    // relate the PortalAlias to the default portal on a fresh database installation
                    DataProvider.Instance().UpdatePortalAlias(httpAlias.ToLowerInvariant().Trim('/'), UserController.Instance.GetCurrentUserInfo().UserID);
                    EventLogController.Instance.AddLog(
                        "PortalAlias",
                        httpAlias,
                        PortalController.Instance.GetCurrentSettings(),
                        UserController.Instance.GetCurrentUserInfo().UserID,
                        EventLogController.EventLogType.PORTALALIAS_UPDATED);

                    // clear the cachekey "GetPortalByAlias" otherwise portalalias "_default" stays in cache after first install
                    DataCache.RemoveCache("GetPortalByAlias");

                    // try again
                    portalAlias = this.GetPortalAliasLookupInternal(httpAlias.ToLowerInvariant());
                }
            }

            return(portalAlias);
        }