示例#1
0
        private static PageSettings LoadPage(PageSettings page)
        {
            SiteSettings siteSettings = GetCurrentSiteSettings();

            if (siteSettings == null)
            {
                return(null);
            }

            bool   useFolderForSiteDetection = WebConfigSettings.UseFolderBasedMultiTenants;
            string virtualFolder;

            if (useFolderForSiteDetection)
            {
                virtualFolder = VirtualFolderEvaluator.VirtualFolderName();
            }
            else
            {
                virtualFolder = string.Empty;
            }


            //PageSettings currentPage = new PageSettings(siteSettings.SiteId, pageID);
            PageSettings currentPage = page;

            if (currentPage.SiteId != siteSettings.SiteId)
            {               // probably url manipulation trying to use a pageid that
                // doesn't belong to the site so just return the home page
                currentPage = new PageSettings(siteSettings.SiteId, siteSettings.HomePageOverride);
            }

            if (
                (useFolderForSiteDetection) &&
                (virtualFolder.Length > 0) &&
                (currentPage.Url.StartsWith("~/"))
                )
            {
                currentPage.Url = currentPage.Url.Replace("~/", "~/" + virtualFolder + "/");

                currentPage.UrlHasBeenAdjustedForFolderSites = true;
            }

            if (
                (useFolderForSiteDetection) &&
                (virtualFolder.Length > 0) &&
                (!currentPage.UseUrl)
                )
            {
                currentPage.Url    = "~/" + virtualFolder + "/Default.aspx?pageid=" + currentPage.PageId.ToString();
                currentPage.UseUrl = true;
                currentPage.UrlHasBeenAdjustedForFolderSites = true;
            }

            LoadPageModule(currentPage);

            return(currentPage);
        }
示例#2
0
        private static SiteSettings GetSiteSettingsFromCache()
        {
            bool   useFolderForSiteDetection = WebConfigSettings.UseFolderBasedMultiTenants;
            string cachekey;
            int    siteId;

            if (useFolderForSiteDetection)
            {
                string siteFolderName = VirtualFolderEvaluator.VirtualFolderName();
                if (siteFolderName.Length == 0)
                {
                    siteFolderName = "root";
                }
                siteId   = SiteSettings.GetSiteIdByFolder(siteFolderName);
                cachekey = "SiteSettings_" + siteId.ToInvariantString();
            }
            else
            {
                //todo: cache number of sites in db when application starts (or when sites are added) then, if there's only one, we don't need to go to db to get the siteid
                //maybe we could cache all of the hostnames and site ids?
                String hostName = WebUtils.GetHostName();
                siteId   = SiteSettings.GetSiteIdByHostName(hostName);
                cachekey = "SiteSettings_" + siteId.ToInvariantString();
            }

            DateTime expiration = DateTime.Now.AddSeconds(WebConfigSettings.SiteSettingsCacheDurationInSeconds);

            try
            {
                SiteSettings siteSettings = CacheManager.Cache.Get <SiteSettings>(cachekey, expiration, () =>
                {
                    // This is the anonymous function which gets called if the data is not in the cache.
                    // This method is executed and whatever is returned, is added to the cache with the passed in expiry time.
                    SiteSettings site = LoadSiteSettings();
                    return(site);
                });

                return(siteSettings);
            }
            catch (Exception ex)
            {
                log.Error("failed to get siteSettings from cache so loading it directly", ex);
                return(LoadSiteSettings());
            }
        }
示例#3
0
        private static SiteSettings GetSiteSettingsFromCache()
        {
            bool   useFolderForSiteDetection = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);
            string cachekey;
            int    siteId;

            if (useFolderForSiteDetection)
            {
                string siteFolderName = VirtualFolderEvaluator.VirtualFolderName();
                if (siteFolderName.Length == 0)
                {
                    siteFolderName = "root";
                }
                siteId   = SiteSettings.GetSiteIdByFolder(siteFolderName);
                cachekey = "SiteSettings_" + siteId.ToInvariantString();
            }
            else
            {
                String hostName = WebUtils.GetHostName();
                siteId   = SiteSettings.GetSiteIdByHostName(hostName);
                cachekey = "SiteSettings_" + siteId.ToInvariantString();
            }

            DateTime expiration = DateTime.Now.AddSeconds(WebConfigSettings.SiteSettingsCacheDurationInSeconds);

            try
            {
                SiteSettings siteSettings = CacheManager.Cache.Get <SiteSettings>(cachekey, expiration, () =>
                {
                    // This is the anonymous function which gets called if the data is not in the cache.
                    // This method is executed and whatever is returned, is added to the cache with the passed in expiry time.
                    SiteSettings site = LoadSiteSettings();
                    return(site);
                });

                return(siteSettings);
            }
            catch (Exception ex)
            {
                log.Error("failed to get siteSettings from cache so loading it directly", ex);
                return(LoadSiteSettings());
            }
        }
示例#4
0
        private static Collection <PageSettings> LoadMenuPages()
        {
            Collection <PageSettings> menuPages = new Collection <PageSettings>();

            SiteSettings siteSettings = GetCurrentSiteSettings();

            if (siteSettings == null)
            {
                return(menuPages);
            }

            bool useFolderForSiteDetection
                = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);
            string virtualFolder;

            if (useFolderForSiteDetection)
            {
                virtualFolder = VirtualFolderEvaluator.VirtualFolderName();
            }
            else
            {
                virtualFolder = string.Empty;
            }


            using (IDataReader reader = PageSettings.GetPageList(siteSettings.SiteId))
            {
                int i = 0;
                while (reader.Read())
                {
                    PageSettings pageDetails = new PageSettings();
                    pageDetails.SiteId               = siteSettings.SiteId;
                    pageDetails.PageId               = Convert.ToInt32(reader["PageID"]);
                    pageDetails.ParentId             = Convert.ToInt32(reader["ParentID"]);
                    pageDetails.PageName             = reader["PageName"].ToString();
                    pageDetails.PageMetaDescription  = reader["PageDescription"].ToString();
                    pageDetails.MenuDescription      = reader["MenuDesc"].ToString();
                    pageDetails.MenuImage            = reader["MenuImage"].ToString();
                    pageDetails.PageOrder            = Convert.ToInt32(reader["PageOrder"]);
                    pageDetails.AuthorizedRoles      = reader["AuthorizedRoles"].ToString();
                    pageDetails.EditRoles            = reader["EditRoles"].ToString();
                    pageDetails.DraftEditOnlyRoles   = reader["DraftEditRoles"].ToString();
                    pageDetails.CreateChildPageRoles = reader["CreateChildPageRoles"].ToString();


                    pageDetails.UseUrl             = Convert.ToBoolean(reader["UseUrl"]);
                    pageDetails.Url                = reader["Url"].ToString();
                    pageDetails.UnmodifiedUrl      = reader["Url"].ToString();
                    pageDetails.LinkRel            = reader["LinkRel"].ToString();
                    pageDetails.IncludeInMenu      = Convert.ToBoolean(reader["IncludeInMenu"]);
                    pageDetails.IncludeInSiteMap   = Convert.ToBoolean(reader["IncludeInSiteMap"]);
                    pageDetails.ExpandOnSiteMap    = Convert.ToBoolean(reader["ExpandOnSiteMap"]);
                    pageDetails.IncludeInSearchMap = Convert.ToBoolean(reader["IncludeInSearchMap"]);
                    pageDetails.IsClickable        = Convert.ToBoolean(reader["IsClickable"]);
                    pageDetails.ShowHomeCrumb      = Convert.ToBoolean(reader["ShowHomeCrumb"]);
                    pageDetails.RequireSsl         = Convert.ToBoolean(reader["RequireSSL"]);
                    if (reader["PubDateUtc"] != DBNull.Value)
                    {
                        pageDetails.PubDateUtc = Convert.ToDateTime(reader["PubDateUtc"]);
                    }

                    if (
                        (useFolderForSiteDetection) &&
                        (virtualFolder.Length > 0) &&
                        (pageDetails.Url.StartsWith("~/"))
                        )
                    {
                        pageDetails.Url
                            = pageDetails.Url.Replace("~/", "~/" + virtualFolder + "/");
                        pageDetails.UrlHasBeenAdjustedForFolderSites = true;
                    }

                    if (
                        (useFolderForSiteDetection) &&
                        (virtualFolder.Length > 0) &&
                        (!pageDetails.UseUrl)
                        )
                    {
                        pageDetails.UnmodifiedUrl = "~/Default.aspx?pageid="
                                                    + pageDetails.PageId.ToString(CultureInfo.InvariantCulture);

                        pageDetails.Url
                            = "~/" + virtualFolder + "/Default.aspx?pageid="
                              + pageDetails.PageId.ToString(CultureInfo.InvariantCulture);
                        pageDetails.UseUrl = true;
                        pageDetails.UrlHasBeenAdjustedForFolderSites = true;
                    }


                    pageDetails.OpenInNewWindow          = Convert.ToBoolean(reader["OpenInNewWindow"]);
                    pageDetails.ShowChildPageMenu        = Convert.ToBoolean(reader["ShowChildPageMenu"]);
                    pageDetails.ShowChildPageBreadcrumbs = Convert.ToBoolean(reader["ShowChildBreadCrumbs"]);
                    pageDetails.PageIndex = i;

                    string cf = reader["ChangeFrequency"].ToString();
                    switch (cf)
                    {
                    case "Always":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Always;
                        break;

                    case "Hourly":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Hourly;
                        break;

                    case "Daily":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Daily;
                        break;

                    case "Monthly":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Monthly;
                        break;

                    case "Yearly":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Yearly;
                        break;

                    case "Never":
                        pageDetails.ChangeFrequency = PageChangeFrequency.Never;
                        break;

                    case "Weekly":
                    default:
                        pageDetails.ChangeFrequency = PageChangeFrequency.Weekly;
                        break;
                    }

                    string smp = reader["SiteMapPriority"].ToString().Trim();
                    if (smp.Length > 0)
                    {
                        pageDetails.SiteMapPriority = smp;
                    }

                    if (reader["LastModifiedUTC"] != DBNull.Value)
                    {
                        pageDetails.LastModifiedUtc = Convert.ToDateTime(reader["LastModifiedUTC"]);
                    }

                    pageDetails.PageGuid   = new Guid(reader["PageGuid"].ToString());
                    pageDetails.ParentGuid = new Guid(reader["ParentGuid"].ToString());


                    pageDetails.HideAfterLogin = Convert.ToBoolean(reader["HideAfterLogin"]);

                    pageDetails.SiteGuid     = new Guid(reader["SiteGuid"].ToString());
                    pageDetails.CompiledMeta = reader["CompiledMeta"].ToString();
                    if (reader["CompiledMetaUtc"] != DBNull.Value)
                    {
                        pageDetails.CompiledMetaUtc = Convert.ToDateTime(reader["CompiledMetaUtc"]);
                    }

                    pageDetails.IsPending = Convert.ToBoolean(reader["IsPending"]);

                    pageDetails.PubTeamId             = new Guid(reader["PubTeamId"].ToString());
                    pageDetails.IncludeInChildSiteMap = Convert.ToBoolean(reader["IncludeInChildSiteMap"]);

                    pageDetails.BodyCssClass = reader["BodyCssClass"].ToString();
                    pageDetails.MenuCssClass = reader["MenuCssClass"].ToString();

                    pageDetails.PublishMode = Convert.ToInt32(reader["PublishMode"]);

                    menuPages.Add(pageDetails);
                    i++;
                }
            }

            return(menuPages);
        }
示例#5
0
        private static PageSettings LoadPage(Guid pageGuid)
        {
            SiteSettings siteSettings = GetCurrentSiteSettings();

            if (siteSettings == null)
            {
                return(null);
            }

            bool useFolderForSiteDetection
                = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);
            string virtualFolder;

            if (useFolderForSiteDetection)
            {
                virtualFolder = VirtualFolderEvaluator.VirtualFolderName();
            }
            else
            {
                virtualFolder = string.Empty;
            }


            //PageSettings currentPage = new PageSettings(siteSettings.SiteId, pageID);
            PageSettings currentPage = new PageSettings(pageGuid);

            if (currentPage.SiteId != siteSettings.SiteId)
            {   // probably url manipulation trying to use a pageid that
                // doesn't belong to the site so just return the home page
                currentPage = new PageSettings(siteSettings.SiteId, -1);
            }



            if (
                (useFolderForSiteDetection) &&
                (virtualFolder.Length > 0) &&
                (currentPage.Url.StartsWith("~/"))
                )
            {
                currentPage.Url
                    = currentPage.Url.Replace("~/", "~/" + virtualFolder + "/");

                currentPage.UrlHasBeenAdjustedForFolderSites = true;
            }

            if (
                (useFolderForSiteDetection) &&
                (virtualFolder.Length > 0) &&
                (!currentPage.UseUrl)
                )
            {
                currentPage.Url
                    = "~/" + virtualFolder + "/Default.aspx?pageid="
                      + currentPage.PageId.ToString();
                currentPage.UseUrl = true;
                currentPage.UrlHasBeenAdjustedForFolderSites = true;
            }

            LoadPageModule(currentPage);

            return(currentPage);
        }
示例#6
0
        private static SiteSettings LoadSiteSettings()
        {
            if (debugLog)
            {
                log.Debug("CacheHelper.cs LoadSiteSettings");
            }

            SiteSettings siteSettings = null;

            try
            {
                bool useFolderForSiteDetection = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false);

                string siteFolderName;
                if (useFolderForSiteDetection)
                {
                    siteFolderName = VirtualFolderEvaluator.VirtualFolderName();
                }
                else
                {
                    siteFolderName = string.Empty;
                }

                if (useFolderForSiteDetection)
                {
                    Guid siteGuid = SiteFolder.GetSiteGuid(siteFolderName);
                    siteSettings = new SiteSettings(siteGuid);
                }
                else
                {
                    siteSettings = new SiteSettings(WebUtils.GetHostName());
                }

                if (siteSettings.SiteId > -1)
                {
                    siteSettings.ReloadExpandoProperties();
                    siteSettings.SiteRoot = WebUtils.GetSiteRoot();
                    if (useFolderForSiteDetection)
                    {
                        siteSettings.SiteFolderName = siteFolderName;
                    }
                }
                else
                {
                    siteSettings = null;
                    log.Error("CacheHelper failed to load siteSettings");
                }
            }
            catch (System.Data.Common.DbException ex)
            {
                log.Error("Error trying to obtain siteSettings", ex);
            }
            catch (InvalidOperationException ex)
            {
                log.Error("Error trying to obtain siteSettings", ex);
            }
            catch (IndexOutOfRangeException ex)
            {
                log.Error("Error trying to obtain siteSettings", ex);
            }

            return(siteSettings);
        }