1
votes

I have an asp.net website with different user types like admin, registered user. Each user type has different menu options.

I have created a common master page for all types of users, but designed different sitemap files for different user types.

What I am trying to do is, after login according to the user type the sitemap should change in Master Page.

Here is the code I tried in master page loading. It is showing me error like

**The SiteMapProvider 'Principal.sitemap' cannot be found.**

I tried with and without .sitemap extension. (I have principal.sitemap and other sitemaps)

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["usertype"] == null)
        {
            Response.Redirect("loginpage.aspx");
            return;
        }

        String usertype = Session["usertype"].ToString();

        if (usertype == "Principal")
        {
            SiteMapDataSource1.SiteMapProvider = "Principal.sitemap";
        }
        else if (usertype == "Administrator")
        {

            //SiteMapDataSource1.SiteMapProvider = "Administrator";
        }
        else if (usertype == "Student")
        {
            SiteMapDataSource1.SiteMapProvider = "Student";

        }
        foo.DataBind(); 
}

Here is my Master Page aspx code part.

 <asp:SiteMapDataSource  ID="SiteMapDataSource1" ShowStartingNode="false" runat="server" />
                <ul id="cssmenu1">
                    <li><a id="A1" href="index.aspx" runat="server">Home</a></li>

                    <asp:Repeater ID="foo" DataSourceID="SiteMapDataSource1" EnableViewState="false" 
                                    runat="server" onitemcommand="foo_ItemCommand">
                        <ItemTemplate>
                            <li>
                                <a href='<%#Eval("url") %>'><%#Eval("Title") %></a>

                                <ul>
                                    <asp:Repeater ID="bar" DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>' runat="server">
                                        <ItemTemplate>
                                            <li><a href='<%#Eval("url") %>'><%#Eval("Title") %></a></li>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </ul>

                            </li>
                        </ItemTemplate>
                    </asp:Repeater>
                </ul>
            </div>
1
are you sure path of the sitemap is correct?Bobby

1 Answers

1
votes

Have you registered them in your web.config as this question demonstrates?

How to use multiple .sitemap files in ASP.NET

Is so, you may need to check that the name is qualified properly.