470,826 Members | 1,941 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,826 developers. It's quick & easy.

dynamic sitemap binding.

I am using asp.net 2.0 to bind my menu controls using xml
web.sitemaps. I created a sitemap for each role, and what I am trying
to do is dynamically bind the menucontrol's datasource with the
appropriate sitemap based on the logged in user's role. It is not
working though. Any ideas?

//Master Page Code Behind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

//Load SiteMap
MyMenu.DataSource =
GetMenuDataSource(Server.MapPath("~"));
MyMenu.DataBind();
}
}

private XmlDataSource GetMenuDataSource(string serverMapPath)
{
XmlDataSource objData = new XmlDataSource();
objData.XPath = "siteMap/siteMapNode";

if (Roles.IsUserInRole("Admin"))
{
objData.DataFile = serverMapPath + @"\App_Data
\admin.sitemap";
}
else if (Roles.IsUserInRole("Public"))
{
objData.DataFile = serverMapPath + @"\App_Data
\public.sitemap";
}
else if (Roles.IsUserInRole("Private"))
{
objData.DataFile = serverMapPath + @"\App_Data
\private.sitemap";
}

objData.DataBind();
return objData;
}
Jul 10 '08 #1
1 2534
On 10 Jul, 21:32, carlos <ubuntu4car...@yahoo.comwrote:
I am using asp.net 2.0 to bind my menu controls using xml
web.sitemaps. I created a sitemap for each role, and what I am trying
to do is dynamically bind the menucontrol's datasource with the
appropriate sitemap based on the logged in user's role. It is not
working though. Any ideas?

//Master Page Code Behind
*protected void Page_Load(object sender, EventArgs e)
* * * * {
* * * * * * if (!IsPostBack)
* * * * * * {

* * * * * * * * //Load SiteMap
* * * * * * * * MyMenu.DataSource =
GetMenuDataSource(Server.MapPath("~"));
* * * * * * * * MyMenu.DataBind();
* * * * * * }

* * * * }

*private XmlDataSource GetMenuDataSource(string serverMapPath)
* * * * {
* * * * * * XmlDataSource objData = new XmlDataSource();
* * * * * * objData.XPath = "siteMap/siteMapNode";

* * * * * * if (Roles.IsUserInRole("Admin"))
* * * * * * {
* * * * * * * * objData.DataFile = serverMapPath + @"\App_Data
\admin.sitemap";
* * * * * * }
* * * * * * else if (Roles.IsUserInRole("Public"))
* * * * * * {
* * * * * * * * objData.DataFile = serverMapPath + @"\App_Data
\public.sitemap";
* * * * * * }
* * * * * * else if (Roles.IsUserInRole("Private"))
* * * * * * {
* * * * * * * * objData.DataFile = serverMapPath + @"\App_Data
\private.sitemap";
* * * * * * }

* * * * * * objData.DataBind();
* * * * * * return objData;
* * * * }
No need to do it that way. Use a single Sitemap file and for each of
the restricted nodes add an attribute roles="..."
Jul 10 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by festiv | last post: by
4 posts views Thread by Robert Camsky | last post: by
1 post views Thread by Danial | last post: by
3 posts views Thread by Ray Booysen | last post: by
3 posts views Thread by Smokey Grindel | last post: by
2 posts views Thread by =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.