Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide the menu of Master page until the user do login in asp.net

I create a master page with a navigation bar. I made index page as a login page, so I use the login control in index.aspx which is registered under the master page.

Now my question is how can I hide the navigation bar which is in master page until the user do login, after the user doing successful login the navigation bar should appear

like image 516
HTML Man Avatar asked Feb 05 '12 13:02

HTML Man


3 Answers

Use this in the Master Page (C# code)

<% if (HttpContext.Current.User.Identity.IsAuthenticated ) { %>

<div>navigation html when is authenticated</div>

<% } else { %>

<div>navigation html when is NOT authenticated</div>

<% } %>
like image 141
Adrian Iftode Avatar answered Oct 14 '22 07:10

Adrian Iftode


In webforms you can use the LoginView control to display different content depending on the user's authentication status:

<asp:LoginView ID="LoginView1" Runat="server">
  <LoggedInTemplate>
   <div>Navigation Bar</div>
  </LoggedInTemplate>
  <AnonymousTemplate>
    <div>Unauthenticated content</div>
  </AnonymousTemplate>
</asp:LoginView>
like image 45
PHeiberg Avatar answered Oct 14 '22 06:10

PHeiberg


 protected void Page_Load(object sender, EventArgs e)    
{        
        String path = HttpContext.Current.Request.Url.AbsolutePath;

        if (path == "/login.aspx")
        {
            Menu1.Visible = false;
        }       
    }
like image 20
Lina T Avatar answered Oct 14 '22 06:10

Lina T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!