I have an issue with my Menu control not refreshing.. it behaves as if it's being cached or something. My menu is being loaded from an XmlDataSource which defines the conditions when certain menu items should be enabled or disabled.
Hopefully this won't be too confusing... If i load a page that has a menu item enabled, switch to a condition in my application that makes that item disabled, it's still enabled on that page. (for what it's worth, the condition is changing a database environment)... Anyway, if i navigate to another page that hasn't been viewed yet, it is properly disabled. But, even when i navigate back to the first page, it's still incorrectly enabled. if i edit that page and refresh it, then it's properly disabled. so it seems to me like a cache issue, but i have no caching on the site at all.
My source is below. I've tried setting the datasource of the menu control to null, setting it back to the xmldatasource, and rebinding the data on every page_load, but that doesn't work. This is just a simple web user control and i place it on a page.. The code is EXECUTING in the !Page.IsPostback block in the user control, but the menu itself is not refreshing. any ideas?
Menu Control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs" Inherits="MyApp.Controls.Menu" %>
<asp:Menu ID="MenuMain" runat="server" datasourceid="XmlDataSourceMain" orientation="horizontal">
<DataBindings>
<asp:MenuItemBinding DataMember="siteMapNode" TextField="title" NavigateUrlField="url" enabledfield="enabled" />
</DataBindings>
</asp:Menu>
<
asp:xmldatasource runat="server" id="XmlDataSourceMain" xpath="siteMap/siteMapNode" />
Menu Codebehind
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {
SetSecurity();
XmlDataSourceMain.Data = GetMenuData();
}
}
protected string GetMenuData()
{
XmlDocument xmlDoc = LoadMenuConfigFile();
XPathNavigator navigator = xmlDoc.CreateNavigator();
XPathNodeIterator iterator = navigator.SelectDescendants("siteMapNode", String.Empty, false);
while (iterator.MoveNext()) {
bool enabled = false;
string roles = iterator.Current.GetAttribute("roles", String.Empty);
if (!StringUtil.IsBlank(roles)) {
enabled = IsInRoleList(roles);
}
if (enabled) {
string environments = iterator.Current.GetAttribute("environments", string.Empty);
if (!StringUtil.IsBlank(environments)) {
enabled = IsInEnvironment(environments);
}
}
iterator.Current.CreateAttribute(String.Empty, "enabled", String.Empty, enabled.ToString());
}
return navigator.OuterXml;
}