Exemplo n.º 1
0
        private static bool CheckRedirect(ReadOnlyUrl url, NavigationSiteMapNode node)
        {
            const string method = "CheckRedirect";

            if (EventSource.IsEnabled(Event.Trace))
            {
                EventSource.Raise(Event.Trace, method, "Checking redirect.", Event.Arg("url", url.AbsoluteUri));
            }

            if (node != null)
            {
                // Look for the redirect, and if there is one then do it.

                var redirectUrl = GetRedirectUrl(url, node);
                if (redirectUrl != null)
                {
                    if (EventSource.IsEnabled(Event.Trace))
                    {
                        EventSource.Raise(Event.Trace, method, "Redirect needed.", Event.Arg("url", url.AbsoluteUri), Event.Arg("redirectUrl", redirectUrl.AbsoluteUri));
                    }

                    RedirectPermanently(redirectUrl);
                    return(false);
                }
            }

            if (EventSource.IsEnabled(Event.Trace))
            {
                EventSource.Raise(Event.Trace, method, "No redirect.", Event.Arg("url", url.AbsoluteUri));
            }
            return(true);
        }
Exemplo n.º 2
0
        public override SiteMapNode FindSiteMapNodeFromKey(string key)
        {
            NavigationSiteMapNode siteMapNode;

            lock (_syncLock)
            {
                // Get the url from the page.

                string url = GetUrl(key);

                // Create the attributes for the node.

                var attributes = new NameValueCollection();
                if (IsSecure(url))
                {
                    attributes.Add("security", "Secure");
                }

                // Create the node.

                siteMapNode = new NavigationSiteMapNode(this, Guid.NewGuid().ToString(), url, null, null, null, attributes)
                {
                    ParentNode = _rootNode
                };
            }

            return(siteMapNode);
        }
Exemplo n.º 3
0
        private static string GetActiveTitle(string role, NavigationSiteMapNode node)
        {
            // Check whether a title has been specified for the user's role.

            string title = GetTitle(role, node);

            if (!string.IsNullOrEmpty(title))
            {
                return(title);
            }

            // Check whether the node itself specifies the title.

            title = node.Title;
            if (!string.IsNullOrEmpty(title))
            {
                return(title);
            }

            // Pass onto the parent.

            var parentNode = node.GetParentNode();

            return(parentNode == null ? null : GetActiveTitle(role, parentNode));
        }
Exemplo n.º 4
0
        private static string GetActiveValue(string key, string role, NavigationSiteMapNode node)
        {
            // Check whether a value has been specified for the user's role.

            string value = GetValue(key, role, node);

            if (!string.IsNullOrEmpty(value))
            {
                return(value);
            }

            // Check whether the node itself specifies the value.

            value = node[key];
            if (!string.IsNullOrEmpty(value))
            {
                return(value);
            }

            // Pass onto the parent.

            var parentNode = node.GetParentNode();

            return(parentNode == null ? null : GetActiveValue(key, role, parentNode));
        }
Exemplo n.º 5
0
 public static ReadOnlyUrl GetUrlForNode(NavigationSiteMapNode node, ReadOnlyQueryString queryString)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     return(GetNavigationUrl(node, queryString));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the page, generally the FullName of the page type, for the given URL.
        /// </summary>
        public static string GetPageForUrl(ReadOnlyUrl url)
        {
            Initialise();

            // The page is the key in the site map.

            NavigationSiteMapNode node = GetNode(url);

            return(node != null ? node.Key : null);
        }
Exemplo n.º 7
0
        private static bool CheckSecurity(ReadOnlyUrl url, NavigationSiteMapNode node)
        {
            const string method = "CheckSecurity";

            if (EventSource.IsEnabled(Event.Trace))
            {
                EventSource.Raise(Event.Trace, method, "Checking security.", Event.Arg("url", url.AbsoluteUri));
            }

            if (node != null)
            {
                // Check the security requirements of the node.

                switch (node.Security)
                {
                case NavigationSecurity.Secure:
                    if (url.Scheme != Url.SecureScheme)
                    {
                        var secureUrl = url.AsNonReadOnly();
                        secureUrl.Scheme = Url.SecureScheme;

                        if (EventSource.IsEnabled(Event.Trace))
                        {
                            EventSource.Raise(Event.Trace, method, "Needs to be secure but request is not secure.", Event.Arg("url", url.AbsoluteUri), Event.Arg("secureUrl", secureUrl.AbsoluteUri));
                        }

                        Redirect(secureUrl);
                        return(false);
                    }
                    break;

                case NavigationSecurity.Insecure:
                    if (url.Scheme != Url.InsecureScheme)
                    {
                        var insecureUrl = url.AsNonReadOnly();
                        insecureUrl.Scheme = Url.InsecureScheme;

                        if (EventSource.IsEnabled(Event.Trace))
                        {
                            EventSource.Raise(Event.Trace, method, "Needs to be insecure but request is secure.", Event.Arg("url", url.AbsoluteUri), Event.Arg("insecureUrl", insecureUrl.AbsoluteUri));
                        }

                        Redirect(insecureUrl);
                        return(false);
                    }
                    break;
                }
            }

            if (EventSource.IsEnabled(Event.Trace))
            {
                EventSource.Raise(Event.Trace, method, "No security redirect required.", Event.Arg("url", url.AbsoluteUri));
            }
            return(true);
        }
Exemplo n.º 8
0
        private static ReadOnlyUrl GetRedirectUrl(ReadOnlyUrl url, NavigationSiteMapNode node)
        {
            // Use the node's parent's url as the new url, maintaining the query string and fragment.

            if (!node.Redirect && !node.Rewrite)
            {
                return(null);
            }

            var redirectUrl = GetNavigationUrl(node.NavigationParentNode, url.QueryString).AsNonReadOnly();

            redirectUrl.Fragment = url.Fragment;
            return(redirectUrl);
        }
Exemplo n.º 9
0
        private static NavigationSiteMapNode GetNodeForPage(string page)
        {
            Initialise();
            NavigationSiteMapNode node = FindNode(Normalise(page));

            if (node == null)
            {
                throw new ArgumentException("No page named '" + page + "' was found in the navigation paths.", "page");
            }

            // If the node is a rewrite then return the parent.

            if (node.Rewrite)
            {
                return(node.ParentNode as NavigationSiteMapNode);
            }
            return(node);
        }
Exemplo n.º 10
0
 private static ReadOnlyUrl GetNavigationUrl(NavigationSiteMapNode node, ReadOnlyQueryString queryString)
 {
     return(node.NavigationUrl.Clone(queryString));
 }
Exemplo n.º 11
0
 internal NavigationSiteMapNavigator(NavigationSiteMapNode node)
 {
     xmlNodeInfo = new XmlNodeInfo(node);
     nameTable   = new NameTable();
     nameTable.Add(String.Empty);
 }