By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,470 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,470 IT Pros & Developers. It's quick & easy.

dynamic sitemap binding.

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.