Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 29, 2008 07:58 PM by Durden81
May 16, 2007 02:50 PM|LINK
I have a site where the bulk of it is using standard asp.net sitemap files, but for one section I have link generated dynamically. The sitemap files translate correctly when the user switches languages, as do all the nodes of the custom sitemap apart from
the root node. It appears that once the custom provider is accessed once the root node (only is getting cached).
This is a simplified version of what my sitemap file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap enableLocalization="true" xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="courses.aspx" title="$resources: MySite, PageOne" description="">
<siteMapNode provider="DirectorySiteMapProvider" />
<siteMapNode url="" title="$resources: MySite, PageTwo" description="">
When I step through the code the custom sitemap is returning a tree with all nodes in the correct language, but the root always appears in the first language displayed within the sitemap. The node with a custom provider doesn't like a title attribute and
the provider seems to be running correctly.
Any ideas around this?
Aug 23, 2007 12:33 AM|LINK
I am running into this issues as well.
Any one figured this out?
Oct 24, 2007 09:21 AM|LINK
This is probably too late now, but just in case its still useful for people... In the end I used the work-around of a language-neutral string as the root-node's title, which worked for me at the time.
Since then I've revisited the problem and found the answer. In effect the way I'd written the custom provider I had multiple sitemaps being created, one in each language. For whatever reason (probably page life-cycle) the root node wasn't getting refreshed
when the XML file nodes and the rest of the custom provider nodes were. By rewriting the code to generate localized nodes the root node of the custom provider started translating. Note that all the nodes need to be localized or once this is done only the root
node translates and the rest of the custom nodes don't.
Briefly, this is what I did. First of all the sitemap file needs to have the enableLocalization attribute set to true, you'll probably already have done that. There's an overload of the SiteMapNode constructor which takes 9 arguments - two of these refer
to implicitResourceKey and explicitResourceKey. Pick one of these to use - for example to implement implicit resources create a resx file containing your translations (with keys like RootNode.Title), then set the ResourceKey property of the provider to the
name of the resx file. Finally in the node constructor set implicitResourceKey to "RootNode". Explicit keys are similar, except you provide a NameValueCollection to define where the translations are coming from. You'll also want to implement a custom
localization provider instead of using resx files if you have more than a few nodes or if they change regularly.
Hope that helps a bit
Nov 04, 2007 11:28 PM|LINK
Can you please elaborate more or even perhaps show some codes as to how you get the root node translated? Any help you can provide will be greatly appreciated. Thx.
Feb 13, 2008 08:44 AM|LINK
I have the same exact problem and I can't find a solution.
You can find the detailed description (and also get some points) at expert-exchange:
I'll also copy and paste here:
I have tried what I understood from the post but it didn't work.
In my Custom provider (see code attached) first Initialize() is called by asp.net and I create the rootNode with the overload with 9 arguments. However the localization doesn't happen and the text "this is inside the function" is displayed instead (see function
if I put the localized text directly in the Text and Description property of m_rootNode then it displays fine but it will not update if the user changes selection of language. It will always stay with the initial localization (In fact, debugging I also
noticed that Initialize() is never executed again by Asp.net after the first call and neither is GetRootNodeCore()).
Only GetChildNodes(SiteMapNode node) is called after initialization, and in fact all the child nodes localize fine(see function GetChildNodes)
Any idea what I am doing wrong or how to solve this?
public override void Initialize(string providerName, NameValueCollection attributes)
m_template = new XmlSiteMapProvider();
SiteMapNode templateRootNode = m_template.RootNode;
m_rootNode = new SiteMapNode(this, "Root", templateRootNode.Url,
"this is inside the function",
"this is inside the function", null, null, null, "PropertyListings"
public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
if (node.Key == "Root")
// only Root doesnt contain real childs
// they are reloaded
SiteMapNode templateRootNode = m_template.RootNode;
SiteMapNode fakeRoot = new SiteMapNode(this, "Root");
fakeRoot.ChildNodes = new SiteMapNodeCollection();
Dictionary<string, string> macroses = new Dictionary<string, string>();
CopyChildrenTo(fakeRoot, templateRootNode, macroses);
SiteMapNode n = GetNode(m_rootNode.ChildNodes, node.Key);
if (n != null)
return new SiteMapNodeCollection();
Apr 29, 2008 06:42 PM|LINK
Hasy anyone had any luck in this area yet? I'm struggling with the SiteMapNode localization not working as well--I'm using the SqlSiteMap provider taken from msdn.
Apr 29, 2008 07:58 PM|LINK
Unfortunately I didn't find a "proper" solution to this.
But I used a workaround that works fine and so I didn't look more in depth:
1. Bind the control (in my case it was a TreeView control) to the sitemap provider with the wrong localization of the root
2. Make sure the control that uses the sitemap provider is in a UserControl
3. In Page_Load of the code behind of this user control manually change the Text property of the node that has the problem explicitely from a Local or Global resource file.
(I.e. rootElement.Text = Resources.Name.sitemap.root_keyname;)
Done. since it's only 1 element this would not affect performance.
Let me know if this helps..
But if you find the proper solution it would interesting to see it