Exemplo n.º 1
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            string micrositeName = requestContext.RouteData.Values.ContainsKey("Microsite") ? requestContext.RouteData.Values["Microsite"].ToString() : string.Empty;
            string pageName      = requestContext.RouteData.Values.ContainsKey("CMPage") ? requestContext.RouteData.Values["CMPage"].ToString() : requestContext.RouteData.Values["MicrositeOrCMPage"].ToString();
            string virtualPath   = string.Empty;
            string templateName  = string.Empty;

            if (File.Exists(requestContext.HttpContext.Server.MapPath("~/") + pageName + (pageName.EndsWith(".aspx") ? "" : ".aspx")))
            {
                virtualPath = "~/" + pageName + (pageName.EndsWith(".aspx") ? "" : ".aspx");
                if (!String.IsNullOrEmpty(micrositeName))
                {
                    CMSHelpers.SetCurrentRequestCMSMicrosite(CMMicrosite.CMMicrositeGetByName(micrositeName.Replace("-", " ")).FirstOrDefault(), requestContext.HttpContext.ApplicationInstance.Context);
                }
            }
            else
            {
                SEOData seo = SEOData.SEODataGetByFriendlyFilename(pageName).Find(s => s.Approved && (!s.LanguageID.HasValue || s.LanguageID == Helpers.GetCurrentLanguage().LanguageID));
                if (!String.IsNullOrEmpty(micrositeName) && seo == null)
                {
                    seo = SEOData.SEODataGetByFriendlyFilename(micrositeName + "/" + pageName).Find(s => s.Approved && (!s.LanguageID.HasValue || s.LanguageID == Helpers.GetCurrentLanguage().LanguageID));
                }
                if (seo != null)
                {
                    virtualPath = seo.PageURL;
                    if (!String.IsNullOrEmpty(micrositeName))
                    {
                        CMSHelpers.SetCurrentRequestCMSMicrosite(CMMicrosite.CMMicrositeGetByName(micrositeName.Replace("-", " ")).FirstOrDefault(), requestContext.HttpContext.ApplicationInstance.Context);
                    }
                }
                else
                {
                    CMPage      cmsPage         = null;
                    CMMicrosite micrositeEntity = null;
                    if (Classes.ContentManager.Settings.EnableMicrosites)
                    {
                        micrositeEntity = CMMicrosite.CMMicrositeGetByName((!String.IsNullOrEmpty(micrositeName) ? micrositeName : pageName).Replace("-", " ")).FirstOrDefault();
                        if (micrositeEntity != null && String.IsNullOrEmpty(micrositeName))
                        {
                            cmsPage = CMPage.CMPagePage(0, 0, "", "", true, new CMPage.Filters {
                                FilterCMPageFileName = "Home" + (Globals.Settings.RequireASPXExtensions ? ".aspx" : string.Empty), FilterCMPageDeleted = false.ToString(), FilterCMPageCMMicrositeID = micrositeEntity.CMMicroSiteID.ToString()
                            }).FirstOrDefault(c => !c.OriginalCMPageID.HasValue);
                        }
                    }
                    if (cmsPage == null)
                    {
                        cmsPage = CMPage.CMPagePage(0, 0, "", "", true, new CMPage.Filters {
                            FilterCMPageDeleted = false.ToString(), FilterCMPageFileName = pageName, FilterCMPageCMMicrositeID = (micrositeEntity != null ? micrositeEntity.CMMicroSiteID.ToString() : null)
                        }).FirstOrDefault(c => !c.OriginalCMPageID.HasValue);
                    }

                    if (cmsPage == null || !cmsPage.CMTemplateID.HasValue)                     //No templateID means its a global region since programmed pages wouldn't be hitting this
                    {
                        requestContext.HttpContext.Response.Redirect("~/" + (!String.IsNullOrEmpty(micrositeName) ? micrositeName + "/" : string.Empty) + "404.aspx?page=" + pageName);
                    }
                    else
                    {
                        CMTemplate cmTemplate = CMTemplate.GetByID(cmsPage.CMTemplateID.Value);
                        CMSHelpers.SetCurrentRequestCMSPage(cmsPage, requestContext.HttpContext.ApplicationInstance.Context);
                        if (micrositeEntity != null)
                        {
                            CMSHelpers.SetCurrentRequestCMSMicrosite(micrositeEntity, requestContext.HttpContext.ApplicationInstance.Context);
                        }
                        templateName = cmTemplate.FileName;
                        virtualPath  = "~/" + templateName + "?filename=" + pageName;
                    }
                }
            }
            //Showcase hardcoding fix
            virtualPath = virtualPath.Replace("~/home-details", "~/showcase-item.aspx");
            string queryString = ((virtualPath.Contains("?") ? "&" : "?") + requestContext.HttpContext.Request.QueryString).TrimEnd('?').TrimEnd('&');

            HttpContext.Current.RewritePath(virtualPath + queryString, false);
            try
            {
                return((Page)BuildManager.CreateInstanceFromVirtualPath(virtualPath.Split('?')[0], typeof(Page)));
            }
            catch (Exception ex)
            {
                if (!String.IsNullOrEmpty(templateName) && ex.Message.Contains(templateName))
                {
                    throw new Exception("Could not load the page.  Does the CMS Template file '" + virtualPath.Split('?')[0] + "' exist?");
                }
                else
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 2
0
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        string masterPageCss = ((HtmlLink)Page.Master.FindControl("uxCSSFiles")).Href;
        string cmsCss        = "~/css/contentManager.css";

        if (!masterPageCss.Contains(cmsCss))
        {
            ((HtmlLink)Page.Master.FindControl("uxCSSFiles")).Href = masterPageCss + (String.IsNullOrEmpty(masterPageCss) ? "" : ",") + cmsCss;
        }
        if (!Page.ClientScript.IsStartupScriptRegistered("Validate"))
        {
            Page.ClientScript.RegisterStartupScript(typeof(string), "Validate", @"<script language=""javascript"" type=""text/javascript"" src=""//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js""></script>");
        }

        CMPage      cmsPage         = CMSHelpers.GetCurrentRequestCMSPage();
        CMMicrosite micrositeEntity = CMSHelpers.GetCurrentRequestCMSMicrosite();
        string      fileName        = string.Empty;

        if (cmsPage == null)
        {
            fileName = Helpers.GetFileName();
            cmsPage  = CMPage.CMPageGetByFileName(fileName).FirstOrDefault();
            if (cmsPage != null)
            {
                CMSHelpers.SetCurrentRequestCMSPage(cmsPage);
            }
        }
        if (cmsPage != null && Settings.EnableCMPageRoles && !IsDeveloper && !CMSHelpers.CanUserManagePage() && !CMSHelpers.CanUserAccessPage(cmsPage.CMPageID))
        {
            Response.Redirect(FormsAuthentication.LoginUrl + "?ReturnUrl=" + (micrositeEntity == null ? "" : micrositeEntity.Name.Replace(" ", "-") + "/") + cmsPage.FileName.Replace(" ", "-"));
        }
        if (cmsPage == null || (micrositeEntity != null && (!micrositeEntity.Active && !(CMSHelpers.CanUserManagePage() || micrositeEntity.Published || User.IsInRole("Admin") || User.IsInRole("CMS Admin")))))
        {
            Response.Redirect("~/404.aspx?page=" + (micrositeEntity == null ? "" : micrositeEntity.Name.Replace(" ", "-") + "/") + fileName);
        }

        if (cmsPage != null)
        {
            if (micrositeEntity != null)
            {
                m_MicrositeName = micrositeEntity.Name;
            }
            ComponentAdditionalLink = "~/admin/content-manager/content-manager-page.aspx?id=" + cmsPage.CMPageID + "&frontendView=true";
            //Uncomment the following lines if you have the Dynamic Header installed
            ContentPlaceHolder contentDynamicHeader = Helpers.FindContentPlaceHolder(Master, "ContentDynamicHeader");
            if (contentDynamicHeader != null)
            {
                contentDynamicHeader.Visible = false;
                if (cmsPage.DynamicCollectionID.HasValue)
                {
                    Classes.DynamicHeader.DynamicCollection collection = Classes.DynamicHeader.DynamicCollection.GetByID(cmsPage.DynamicCollectionID.Value);
                    if (collection.Active)
                    {
                        BaseDynamicHeader dynamicHeader = (BaseDynamicHeader)contentDynamicHeader.FindControl("uxDynamicHeaderQV");
                        if (dynamicHeader != null)
                        {
                            dynamicHeader.CollectionName = collection.Name;
                            dynamicHeader.Visible        = contentDynamicHeader.Visible = true;
                        }
                    }
                }
            }
        }
    }