コード例 #1
0
        public bool Execute(string url)
        {
            bool _succes = false;

            url = url.Replace(".aspx", string.Empty);
            string currentDomain = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];

            if (url.Length > 0)
            {
                if (url.Substring(0, 1) == "/")
                {
                    url = url.Substring(1, url.Length - 1);
                }

                XmlNode urlNode       = null;
                string  templateAlias = "";

                // We're at domain root
                if (url.IndexOf("/") == -1)
                {
                    if (Domain.Exists(currentDomain))
                    {
                        urlNode = content.Instance.XmlContent.GetElementById(Domain.GetRootFromDomain(currentDomain).ToString());
                    }
                    else
                    {
                        urlNode = content.Instance.XmlContent.GetElementById(Document.GetRootDocuments()[0].Id.ToString());
                    }
                    templateAlias = url.ToLower();
                }
                else
                {
                    string theRealUrl   = url.Substring(0, url.LastIndexOf("/"));
                    string realUrlXPath = LegacyRequestHandler.CreateXPathQuery(theRealUrl, true);
                    urlNode       = content.Instance.XmlContent.SelectSingleNode(realUrlXPath);
                    templateAlias =
                        url.Substring(url.LastIndexOf("/") + 1, url.Length - url.LastIndexOf(("/")) - 1).ToLower();
                }

                if (urlNode != null && Template.GetTemplateIdFromAlias(templateAlias) != 0)
                {
                    _redirectID = int.Parse(urlNode.Attributes.GetNamedItem("id").Value);

                    if (UmbracoConfig.For.UmbracoSettings().WebRouting.DisableAlternativeTemplates == false)
                    {
                        HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate] = templateAlias;
                        HttpContext.Current.Trace.Write("umbraco.altTemplateHandler",
                                                        string.Format("Template changed to: '{0}'", HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate]));
                    }

                    _succes = true;
                }
            }
            return(_succes);
        }
コード例 #2
0
        public bool Execute(string url)
        {
            bool _succes = false;

            url = url.Replace(".aspx", string.Empty);
            if (url.Length > 0)
            {
                if (url.Substring(0, 1) == "/")
                {
                    url = url.Substring(1, url.Length - 1);
                }

                if (url.IndexOf("/") > 0)
                {
                    // Check if we're at the profile page
                    if (url.Substring(0, url.IndexOf("/")) == GlobalSettings.ProfileUrl)
                    {
                        if (_profileId < 0)
                        {
                            // /root added to query to solve umbRuntime bug
                            string _tempQuery =
                                LegacyRequestHandler.CreateXPathQuery(url.Substring(0, url.IndexOf("/")), false);
                            _profileId =
                                int.Parse(
                                    content.Instance.XmlContent.SelectSingleNode(_tempQuery).Attributes.GetNamedItem(
                                        "id").Value);
                        }

                        HttpContext.Current.Items["umbMemberLogin"] =
                            url.Substring(url.IndexOf("/") + 1, url.Length - url.IndexOf("/") - 1);
                        _succes     = true;
                        _redirectID = _profileId;
                    }
                }
            }
            return(_succes);
        }