This is a migrated thread and some comments may be shown as answers.

[Solved] Sitemap changes not updating menu

1 Answer 49 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Philippe
Top achievements
Rank 1
Philippe asked on 17 Mar 2010, 12:12 PM
Some thoughts added to the thread started by "Shawn" on Feb 25, 2010.

I remember reading in another thread that the sitemap is aggressively cached, in a multi-language environment this could have some negative impact if the global cache is used: the sitemap will be cached for every visitor regardless of the language setting of their browser.

Consider the following scenario;
1) the site uses a default language, lets assume "en-US"
2) there are multiple sitemap files, one per language and the URLs are defined in a way that the overflow parameter of the route (ie. the {id} parameter) changes according to the selected language like this:

en-US sitemap
        <siteMapNode title="Root"
            <siteMapNode controller="Home" action="Index/One" title="One" /> 
            <siteMapNode controller="Home" action="Index/Two" title="Two" /> 
        </siteMapNode> 

de-DE sitemap
        <siteMapNode title="Wurzel"
            <siteMapNode controller="Home" action="Index/Eins" title="Eins" /> 
            <siteMapNode controller="Home" action="Index/Zwei" title="Zwei" /> 
        </siteMapNode> 

3) when the visitor hits a page, the controller retrieves the language exposed by the browser, lets assume "de-DE", and selects the sitemap accordingly.

The result will be:
1) the displayed menu is still using "en-US"
2) the routes are internally built using "en-U" thus the overflow parameters are still English words.

This could lead to some interesting results if the site dynamically retrieves the page content either from a database or from another repository based on the UI culture of the current thread.

Adjusting the "<siteMap cacheDurationInMinutes="10">" as suggested by Kazi Manzur Rashid  won't change anything, because the sitemap is apparently cached at the site level and not at the session level.

I tried to map different ViewData keys to different sitemaps based on the language, but it looks like that the sitemap manager only uses the key "SiteMap" to retrieve and load the content of the sitemap file. Running a small project based on these assumptions always returns the following error:

"An item with the same key has already been added. "

The controller looks like this:
    [AutoPopulateSourceCode] 
    [PopulateSiteMap(SiteMapName = "sample", ViewDataKey = "sample")] 
    public class HomeController : Controller 
 

and the action looks like this:
        [PopulateSiteMap(SiteMapName = "sample", ViewDataKey = "sample")] 
        [SourceCodeFile("Sitemap""~/Web1031.sitemap")] 
        [SourceCodeFile("Sitemap""~/Web1033.sitemap")] 
        public ActionResult Index() 
        { 
            if (!SiteMapManager.SiteMaps.ContainsKey("sample")) 
            { 
                SiteMapManager.SiteMaps.Register<XmlSiteMap>("sample", sitmap => 
                    sitmap.LoadFrom(string.Format("~/Web{0}.sitemap"
                    Thread.CurrentThread.CurrentUICulture.LCID))); 
            } 
 
            return View(); 
        } 
 
 

Am I missing something?

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 24 Mar 2010, 06:20 PM
Hello Philippe,

The default path for the sitemap, which XmlSiteMap has is "~/Web.sitemap". If you provide different path the SiteMapManager will try to load it from it.

The problem, which you described, will be caused only if you try to register two sitemaps with the same name. I will suggest you register all localized sitemaps with different names.

If you do not want to cache the sitemaps, you can create them with set cacheDurationInMinutes to "0".

Nevertheless I will forward your suggestion for caching the sitemap per Session to our developers for further investigation and discussion.

I have attached a simple test project which shows how to register XmlSiteMap and populate Menu UI component with it.

Kind regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Menu
Asked by
Philippe
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or