0

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#

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by anuj_sharma
0

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

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.