Guys i need to validate a menu item on my ASP.NET application. The menu item has 4 links (Home, News, About us and Contact us) one of them "News" must not redirect to page if the user has not log on, the other three can redirect even if the user has'nt loggin or log in.
Please help with validating this process using C#

Recommended Answers

All 4 Replies

Add below code to aspx page

<asp:Menu ID="Menu1" runat="server"  Width="164px" OnMenuItemClick="Menu1_MenuItemClick" >
           <Items>
               <asp:MenuItem Text="Home" Value="Home" NavigateUrl="Home.aspx"></asp:MenuItem>
               <asp:MenuItem Text="News" Value="News" NavigateUrl="News.aspx"></asp:MenuItem>
               <asp:MenuItem Text="About Us " Value="About Us " NavigateUrl="AboutUs.aspx"></asp:MenuItem>
               <asp:MenuItem Text="Contact us" Value="Contact us" NavigateUrl="ContactUs.aspx"></asp:MenuItem>
           </Items>
       </asp:Menu>
        <asp:LoginStatus ID="LoginStatus1" runat="server" Style="z-index: 100; left: 39px;
            position: absolute; top: 185px" Width="116px" />

Add the below code to aspx.cs Page

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        if (Menu1.SelectedItem.Text == "News")
        {
            if (LoginStatus1.LoginText == "LogOut")
            {
                Menu1.SelectedItem.Enabled = false;
            }
        }
        else
        {
            Menu1.SelectedItem.Enabled = true;
        }
    }

Try this ..Chithra

The better way would be to enable security trimming in the web.sitemap or whichever xml file that you have used as a source to your menu.

The better way would be to enable security trimming in the web.sitemap or whichever xml file that you have used as a source to your menu.

This security trimming is a new thing to me, tell me more about how do i go about this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.