dynamic sitemap binding.

C

carlos

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;
}
 
S

Stan

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="..."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top