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
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>
<% } %>
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>
protected void Page_Load(object sender, EventArgs e)
{
String path = HttpContext.Current.Request.Url.AbsolutePath;
if (path == "/login.aspx")
{
Menu1.Visible = false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With