asp.net - SiteMapResolve 不触发

标签 asp.net

我遇到了一些问题,SiteMapResolve 在某些页面上触发,但在其他页面上不触发。

这是我的代码。

protected void Page_Load(object sender, EventArgs e)
{
     SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ChangeMapPath);
}

private SiteMapNode ChangeMapPath(Object sender, SiteMapResolveEventArgs e)
{
    if (SiteMap.CurrentNode != null)
    {
        // Clone the current node and all of its relevant parents.
        SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
        SiteMapNode tempNode = currentNode;

        if (clientId != 0 && tempNode.Title.Equals("Client Notes"))
        {
            tempNode.Url = tempNode.Url + EncryptQueryString("ParentId=" + clientId.ToString());
        }
        if (clientId != 0 && tempNode.ParentNode != null && (tempNode.ParentNode.Title.Equals("Client Contacts")))
        {
            tempNode.ParentNode.Url = tempNode.ParentNode.Url + EncryptQueryString("ParentId=" + clientId.ToString());
        }
        else if (tempNode.ParentNode != null)
            tempNode.ParentNode.Url = tempNode.ParentNode.Url;

        return currentNode;
    }
    return null;
}

谢谢。

最佳答案

尝试替换您的代码

SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ChangeMapPath);

foreach (SiteMapProvider mapProvider in SiteMap.Providers)
{
    mapProvider.SiteMapResolve += ChangeMapPath;
}

关于asp.net - SiteMapResolve 不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6954924/

相关文章:

c# - 如何使用 Visual Web Developer 在 Internet 上托管网站

jquery - POST 到 WebAPI Controller 会导致参数为空

c#使用正则表达式查找并替换字符串中的url

asp.net - 如何使用 Process Monitor 确定哪个 DLL 导致 BadImageFormatException

c# - 如何将面板定位在页面底部

c# - ASP.NET Core 在默认域 (*.azurewebsites.net) 上跨 Azure Web 应用程序共享身份 Cookie

c# - 如何在鼠标悬停在 C# Web 应用程序上的 Ms 图表中显示数据

c# - 取消事件 (onchange) 或在 Blazor 中检索旧值

c# - 使用 Linq to sql 在子表中插入数据(3 层架构)

asp.net - 在 Javascript 中访问 ASP.NET 验证器的 isvalid 属性