0
votes

In the sitemap I have several nodes where a route parameter (meetingId) is included when generating the URLs e.g.

<mvcSiteMapNode controller="MeetingAttendants" action="Index" title="Attendants" preservedRouteParameters="meetingId" />

When I browse one meeting (meetingId = 1) and switch to another meeting (meetingId = 2), the menu generated by mvcsitemapprovider does not change.

The node above would generate the URL:

Meetings/1/Attendants/

But should it should actually be:

Meetings/2/Attendants

In my top level node I have changeFrequency="Always":

  <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">

And in web.config I have:

cacheDuration="0"

How come the nodes are cached? And how to solve this issue?

1

1 Answers

0
votes

This is a problem with the DefaultSiteMapNodeUrlResolver that ships with the product. The problem originates from the instantiation of the UrlHelper which uses the current (route) context. This probably contains your meetingid for the current request.

protected UrlHelper UrlHelper
    {
        get
        {
            if (HttpContext.Current.Items[UrlHelperCacheKey] == null)
            {
                RequestContext ctx;
                if (HttpContext.Current.Handler is MvcHandler)
                    ctx = ((MvcHandler)HttpContext.Current.Handler).RequestContext;
                else
                    ctx = new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData());

                HttpContext.Current.Items[UrlHelperCacheKey] = new UrlHelper(ctx);
            }
            return (UrlHelper)HttpContext.Current.Items[UrlHelperCacheKey];
        }
    }

Your best bet is to write your own ISiteMapNodeUrlResolver and simply remove the offending code, such as:

protected UrlHelper UrlHelper
    {
        get
        {
            if (HttpContext.Current.Items[UrlHelperCacheKey] == null)
            {
                var ctx = new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData());

                HttpContext.Current.Items[UrlHelperCacheKey] = new UrlHelper(ctx);
            }
            return (UrlHelper)HttpContext.Current.Items[UrlHelperCacheKey];
        }
    }