// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-
-#if NET_2_0
using System.Collections.Generic;
+using System.Web.Util;
namespace System.Web
{
Dictionary<SiteMapNode, SiteMapNode> nodeToParent;
Dictionary<SiteMapNode, SiteMapNodeCollection> nodeToChildren;
Dictionary<string, SiteMapNode> urlToNode;
-
+
protected StaticSiteMapProvider ()
{
keyToNode = new Dictionary<string, SiteMapNode> ();
urlToNode = new Dictionary<string, SiteMapNode> (StringComparer.InvariantCultureIgnoreCase);
}
- internal void AddNodeInternal (SiteMapNode node, SiteMapNode parentNode, bool callFind)
+ internal protected override void AddNode (SiteMapNode node, SiteMapNode parentNode)
{
if (node == null)
throw new ArgumentNullException ("node");
lock (this_lock) {
- if (callFind && node.Provider == this && FindSiteMapNodeFromKey (node.Key) != null)
- throw new InvalidOperationException (string.Format ("A node with key '{0}' already exists.",node.Key));
-
- if (!String.IsNullOrEmpty (node.Url)) {
- string url = MapUrl (node.Url);
-
- if (callFind && FindSiteMapNode (url) != null)
+ string nodeKey = node.Key;
+ if (FindSiteMapNodeFromKey (nodeKey) != null && node.Provider == this)
+ throw new InvalidOperationException (string.Format ("A node with key '{0}' already exists.",nodeKey));
+
+ string nodeUrl = node.Url;
+ if (!String.IsNullOrEmpty (nodeUrl)) {
+ string url = MapUrl (nodeUrl);
+ SiteMapNode foundNode = FindSiteMapNode (url);
+ if (foundNode != null && String.Compare (foundNode.Url, url, RuntimeHelpers.StringComparison) == 0)
throw new InvalidOperationException (String.Format (
"Multiple nodes with the same URL '{0}' were found. " +
"StaticSiteMapProvider requires that sitemap nodes have unique URLs.",
node.Url
));
-
+
urlToNode.Add (url, node);
}
+ keyToNode.Add (nodeKey, node);
- keyToNode.Add (node.Key, node);
+ if (node == RootNode)
+ return;
if (parentNode == null)
- return;
+ parentNode = RootNode;
nodeToParent.Add (node, parentNode);
children.Add (node);
}
}
-
- internal protected override void AddNode (SiteMapNode node, SiteMapNode parentNode)
- {
- AddNodeInternal (node, parentNode, true);
- }
protected virtual void Clear ()
{
BuildSiteMap();
SiteMapNode node;
- urlToNode.TryGetValue (MapUrl (rawUrl), out node);
+ if (VirtualPathUtility.IsAppRelative (rawUrl))
+ rawUrl = VirtualPathUtility.ToAbsolute (rawUrl, HttpRuntime.AppDomainAppVirtualPath, false);
+
+ if (!urlToNode.TryGetValue (rawUrl, out node))
+ return null;
+
return CheckAccessibility (node);
}
return (node != null && IsAccessibleToUser (HttpContext.Current, node)) ? node : null;
}
- string MapUrl (string url)
+ internal string MapUrl (string url)
{
+ if (String.IsNullOrEmpty (url))
+ return url;
+
+ string appVPath = HttpRuntime.AppDomainAppVirtualPath;
+ if (String.IsNullOrEmpty (appVPath))
+ appVPath = "/";
+
if (VirtualPathUtility.IsAppRelative (url))
- return VirtualPathUtility.ToAbsolute (url);
+ return VirtualPathUtility.ToAbsolute (url, appVPath, true);
else
- return url;
+ return VirtualPathUtility.ToAbsolute (UrlUtils.Combine (appVPath, url), appVPath, true);
}
}
}
-#endif
+