Пример #1
0
        /// <summary>
        /// If this is an enterprise solution, we need to be sure we have the correct site url.
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public virtual string GetSiteUrl(PageData page)
        {
            string hostUrl;

            // Config has highest priority
            hostUrl = Configuration.NewsLetterConfiguration.GetAppSettingsConfigValueEx <string>("Newsletter.BaseUrl", null);
            if (string.IsNullOrEmpty(hostUrl))
            {
                if (page["BaseUrl"] != null)
                {
                    // The host url could be different than what we get from the system
                    // if you have a dedicated edit server for an example.
                    hostUrl = page["BaseUrl"].ToString();
                }
                else
                {
#if CMS9
                    // Always look up based on page
                    SiteDefinitionResolver repo           = ServiceLocator.Current.GetInstance <SiteDefinitionResolver>();
                    SiteDefinition         siteDefinition = repo.GetDefinitionForContent(page.ContentLink, fallbackToWildcardMapped: true, fallbackToEmpty: false);
#else
                    ISiteDefinitionResolver repo           = ServiceLocator.Current.GetInstance <ISiteDefinitionResolver>();
                    SiteDefinition          siteDefinition = repo.GetByContent(page.ContentLink, fallbackToWildcard: true, fallbackToEmpty: false);
#endif
                    if (siteDefinition == null || siteDefinition.SiteUrl == null)
                    {
                        // Still haven't found it, can't go on
                        throw new ApplicationException("Cannot find a SiteDefinition with a valid SiteUrl for page: " +
                                                       page.ContentLink.ToString());
                    }

                    if (_log.IsDebugEnabled())
                    {
                        _log.Debug("Looked up Site Definition: {0}, Url: {1}", siteDefinition.Name,
                                   siteDefinition.SiteUrl);
                        foreach (HostDefinition host in siteDefinition.Hosts)
                        {
                            _log.Debug("Available Site Definition Host: {0} (language: {1})", host.Name, host.Language);
                        }
                    }

                    hostUrl = siteDefinition.SiteUrl.ToString();
                }
            }

            return(hostUrl);
        }
Пример #2
0
        public static string GetSiteUrl(PageData page)
        {
            // Always look up based on page
            SiteDefinitionResolver repo           = ServiceLocator.Current.GetInstance <SiteDefinitionResolver>();
            SiteDefinition         siteDefinition = repo.GetDefinitionForContent(page.ContentLink, fallbackToWildcardMapped: true, fallbackToEmpty: false);

            if (siteDefinition == null || siteDefinition.SiteUrl == null)
            {
                // Still haven't found it, can't go on
                throw new ApplicationException("Cannot find a SiteDefinition with a valid SiteUrl for page: " +
                                               page.ContentLink.ToString());
            }

            string hostUrl = siteDefinition.SiteUrl.ToString();


            return(hostUrl);
        }