ASP.NET站点地图

时间:2008-08-01 15:50:09

标签: sql asp.net xml sitemap

是否有人有创建基于SQL的ASP.NET 站点地图提供程序的经验?

我的默认XML文件web.sitemap可以正常使用我的菜单和 SiteMapPath 控件,但我需要一种方法让我的网站用户动态创建和修改页面。

我还需要将网页查看权限绑定到标准ASP.NET会员系统中。

1 个答案:

答案 0 :(得分:13)

来自MSDN杂志的Jeff Prosise版本运行良好,但它有一些缺陷:

AddNode在您的菜单(www.google.com等)上链接到外部网站

以下是BuildSiteMap()中的修复:

SiteMapNode node = GetSiteMapNodeFromReader(reader);
string url = node.Url;
if (url.Contains(":"))
{
    string garbage = Guid.NewGuid().ToString();  // SiteMapNode needs unique URLs
    node.Url = "~/dummy_" + garbage + ".aspx";
    AddNode(node, _root);
    node.Url = url;
}
else
{
    AddNode(node, _root);
}

SQLDependency缓存很酷,但是如果你不想在每次加载菜单时访问数据库(检查依赖项是否已经改变)并且你的菜单不经常改变那么为什么不使用HttpRuntime.Cache呢?

public override SiteMapNode RootNode
{
    get
    {
        SiteMapNode temp = (SiteMapNode)HttpRuntime.Cache["SomeKeyName"];
        if (temp == null)
        {
            temp = BuildSiteMap();
            HttpRuntime.Cache.Insert("SomeKeyName", temp, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration);
        }
        return temp;
    }
}