Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Site Map Provider Caching Problem

Status
Not open for further replies.

jgd123456

Programmer
Nov 3, 2006
19
GB
Hi, i'm using my own sql server 2005 site map provider. The problem i have is that when i make a change to some of the data in the database it does not update the site map display (some cached version is displayed) unless i restart iis. Here's the code for my site map provider:

Code:
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public class MySqlSiteMapProvider : StaticSiteMapProvider
{
    private SiteMapNode _root = null;
    private Dictionary<int, SiteMapNode> _nodes = new Dictionary<int, SiteMapNode>(1000);

    public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
    {
        base.Initialize(name, config);
    }

    protected override SiteMapNode GetRootNodeCore()
    {
        this.Clear();
        return this.BuildSiteMap();
    }

    public override SiteMapNode BuildSiteMap()
    {
        lock (this)
        {
            // If there is no root node, then there is no site map
            if (_root == null)
            {
                // Start with a clean slate
                this.Clear();

                // Add the root node
                _root = new SiteMapNode(this, "0", "/", "Home", "Home");
                this.AddNode(_root);

                // Now add the menu items
                this.AddMenuItems(null);
            }

            return _root;
        }
    }

    public void AddMenuItems(int? parentID)
    {
        foreach (MenuItemsItem menuItem in MenuItems.GetMenuItemsByParentID(parentID))
        {
            NameValueCollection attributes = new NameValueCollection();
            attributes.Add("ShowInNavigation", menuItem.ShowInNavigation.ToString());
            attributes.Add("ShowInSiteMap", menuItem.ShowInSiteMap.ToString());
            attributes.Add("ShowParentItems", menuItem.ShowParentItems.ToString());

            SiteMapNode node = new SiteMapNode(this, menuItem.MenuItemID.ToString(), menuItem.Path, menuItem.Title, menuItem.Title, null, attributes, null, null);
            _nodes.Add(menuItem.MenuItemID, node);
            this.AddNode(node, menuItem.ParentID == null ? _root : _nodes[(int)menuItem.ParentID]);

            // Now add the sub categories
            this.AddMenuItems(menuItem.MenuItemID);
        }
    }

    protected override void Clear()
    {
        lock (this)
        {
            _root = null;
            _nodes = new Dictionary<int, SiteMapNode>(1000);
            base.Clear();
        }
    }
}

Appreciate if someone could tell me what i am doing wrong.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top