Show/hide sitemap if user is logged in

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PetroTiburcio
    New Member
    • May 2013
    • 10

    Show/hide sitemap if user is logged in

    I have a log in page, code behind is below:

    Code:
    protected void btnLog_Click(object sender, EventArgs e)
    {
    
        SqlConnection conn1 = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbUsers;Integrated Security=True");
        conn1.Open();
    
        SqlCommand cmdd = new SqlCommand("select * from Users where UserName = @user AND Password = @pass", conn1);
    
        SqlParameter param = new SqlParameter();
        SqlParameter param1 = new SqlParameter();
    
        param.ParameterName = "@user";
        param1.ParameterName = "@pass";
    
        param.Value = txtuser.Text;
        param1.Value = txtpass.Text;
    
        cmdd.Parameters.Add(param);
        cmdd.Parameters.Add(param1);
    
        SqlDataReader reader = cmdd.ExecuteReader();
    
        if (reader.HasRows)
        {
            reader.Read();
            MessageBox("Login Successful");
            clear();
        }
        else
        {
            MessageBox("Invalid Username/Password");
        }
    
    }
    I have two sitemaps:

    Code:
    <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" 
                    EnableViewState="False" IncludeStyleBlock="False" Orientation="Horizontal" 
                    DataSourceID="SiteMapDataSource1" StaticDisplayLevels="2" 
                    onmenuitemdatabound="NavigationMenu_MenuItemDataBound">        
                </asp:Menu>      
                <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    
                <div class="clear hideSkiplink">              
                <asp:Menu ID="Menu1" runat="server" CssClass="menu" 
                    EnableViewState="False" IncludeStyleBlock="False" Orientation="Horizontal" 
                    DataSourceID="SiteMapDataSource2" StaticDisplayLevels="2" 
                    onmenuitemdatabound="NavigationMenu_MenuItemDataBound">        
                </asp:Menu>      
                <asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" SiteMapProvider="AdminSiteMapProvider"/>
    What I want to achieve is when a user is not logged in Menu1 will display and NavigationMenu will hide, but if a user is logged in Menu1 will hide then NavigationMenu will show.

    Kindly help me with this. I'm using asp.net with c#. Thanks and God Bless
    Last edited by Frinavale; Jun 12 '13, 05:26 PM.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Use an if structure to display one if they are logged in, and the other if not.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      In the code posted above there is no indication of how you store the fact that the user is logged in.

      This is typically done using an authentication-token cookie or by storing something into Session to indicate that the user has logged in.

      Once you have stored the fact that the user has logged in, all you need to do is check to see they are logged in and set the visibility of your menus etc.

      You should probably do some research into Forms Authentication :)

      -Frinny

      Comment

      Working...