void Page_PreInit(Object sender, EventArgs e)
        {
            Trace.Write("umbracoInit", "handling request");

            if (UmbracoContext.Current == null)
            {
                UmbracoContext.Current = new UmbracoContext(HttpContext.Current);
            }

            bool editMode = UmbracoContext.Current.LiveEditingContext.Enabled;

            if (editMode)
            {
                ValidateRequest = false;
            }

            if (m_tmp != "" && Request["umbPageID"] == null)
            {
                // Check numeric
                string tryIntParse = m_tmp.Replace("/", "").Replace(".aspx", string.Empty);
                int    result;
                if (int.TryParse(tryIntParse, out result))
                {
                    m_tmp = m_tmp.Replace(".aspx", string.Empty);

                    // Check for request
                    if (!string.IsNullOrEmpty(Request["umbVersion"]))
                    {
                        // Security check
                        BasePages.UmbracoEnsuredPage bp = new BasePages.UmbracoEnsuredPage();
                        bp.ensureContext();
                        m_version = new Guid(Request["umbVersion"]);
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Request["umbPageID"]))
                {
                    int result;
                    if (int.TryParse(Request["umbPageID"], out result))
                    {
                        m_tmp = Request["umbPageID"];
                    }
                }
            }

            if (m_version != Guid.Empty)
            {
                HttpContext.Current.Items["pageID"] = m_tmp.Replace("/", "");
                m_umbPage = new page(int.Parse(m_tmp.Replace("/", "")), m_version);
            }
            else
            {
                m_umbRequest = new requestHandler(UmbracoContext.Current.GetXml(), m_tmp);
                Trace.Write("umbracoInit", "Done handling request");
                if (m_umbRequest.currentPage != null)
                {
                    HttpContext.Current.Items["pageID"] = m_umbRequest.currentPage.Attributes.GetNamedItem("id").Value;

                    // Handle edit
                    if (editMode)
                    {
                        Document d = new Document(int.Parse(m_umbRequest.currentPage.Attributes.GetNamedItem("id").Value));
                        m_umbPage = new page(d.Id, d.Version);
                    }
                    else
                    {
                        m_umbPage = new page(m_umbRequest.currentPage);
                    }
                }
            }

            // set the friendly path so it's used by forms
            HttpContext.Current.RewritePath(HttpContext.Current.Items[requestModule.ORIGINAL_URL_CXT_KEY].ToString());

            if (UmbracoSettings.UseAspNetMasterPages)
            {
                HttpContext.Current.Trace.Write("umbracoPage", "Looking up skin information");

                if (m_umbPage != null)
                {
                    if (m_umbPage.Template == 0)
                    {
                        string custom404 = umbraco.library.GetCurrentNotFoundPageId();
                        if (!String.IsNullOrEmpty(custom404))
                        {
                            XmlNode xmlNodeNotFound = content.Instance.XmlContent.GetElementById(custom404);
                            if (xmlNodeNotFound != null)
                            {
                                m_umbPage = new page(xmlNodeNotFound);
                            }
                        }
                    }

                    if (m_umbPage.Template != 0)
                    {
                        this.MasterPageFile = template.GetMasterPageName(m_umbPage.Template);
                    }
                    else
                    {
                        GenerateNotFoundContent();
                        Response.End();
                    }
                }

                initUmbracoPage();
            }
        }
示例#2
0
        void Page_PreInit(Object sender, EventArgs e)
        {
            Trace.Write("umbracoInit", "handling request");

            if (UmbracoContext.Current == null)
                UmbracoContext.Current = new UmbracoContext(HttpContext.Current);

            bool editMode = UmbracoContext.Current.LiveEditingContext.Enabled;

            if (editMode)
                ValidateRequest = false;

            if (m_tmp != "" && Request["umbPageID"] == null)
            {
                // Check numeric
                string tryIntParse = m_tmp.Replace("/", "").Replace(".aspx", string.Empty);
                int result;
                if (int.TryParse(tryIntParse, out result))
                {
                    m_tmp = m_tmp.Replace(".aspx", string.Empty);

                    // Check for request
                    if (!string.IsNullOrEmpty(Request["umbVersion"]))
                    {
                        // Security check
                        BasePages.UmbracoEnsuredPage bp = new BasePages.UmbracoEnsuredPage();
                        bp.ensureContext();
                        m_version = new Guid(Request["umbVersion"]);
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Request["umbPageID"]))
                {
                    int result;
                    if (int.TryParse(Request["umbPageID"], out result))
                    {
                        m_tmp = Request["umbPageID"];
                    }
                }
            }

            if (m_version != Guid.Empty)
            {
                HttpContext.Current.Items["pageID"] = m_tmp.Replace("/", "");
                m_umbPage = new page(int.Parse(m_tmp.Replace("/", "")), m_version);
            }
            else
            {
                m_umbRequest = new requestHandler(UmbracoContext.Current.GetXml(), m_tmp);
                Trace.Write("umbracoInit", "Done handling request");
                if (m_umbRequest.currentPage != null)
                {
                    HttpContext.Current.Items["pageID"] = m_umbRequest.currentPage.Attributes.GetNamedItem("id").Value;

                    // Handle edit
                    if (editMode)
                    {
                        Document d = new Document(int.Parse(m_umbRequest.currentPage.Attributes.GetNamedItem("id").Value));
                        m_umbPage = new page(d.Id, d.Version);
                    }
                    else
                        m_umbPage = new page(m_umbRequest.currentPage);
                }
            }

            // set the friendly path so it's used by forms
            HttpContext.Current.RewritePath(HttpContext.Current.Items[requestModule.ORIGINAL_URL_CXT_KEY].ToString());

            if (UmbracoSettings.UseAspNetMasterPages)
            {
                HttpContext.Current.Trace.Write("umbracoPage", "Looking up skin information");

                if (m_umbPage != null)
                {
                    if (m_umbPage.Template == 0)
                    {
                        string custom404 = umbraco.library.GetCurrentNotFoundPageId();
                        if (!String.IsNullOrEmpty(custom404))
                        {
                            XmlNode xmlNodeNotFound = content.Instance.XmlContent.GetElementById(custom404);
                            if (xmlNodeNotFound != null)
                            {
                                m_umbPage = new page(xmlNodeNotFound);
                            }
                        }
                    }

                    if (m_umbPage.Template != 0)
                    {
                        this.MasterPageFile = template.GetMasterPageName(m_umbPage.Template);
                    }
                    else
                    {
                        GenerateNotFoundContent();
                        Response.End();
                    }
                }

                initUmbracoPage();
            }
        }