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.
我创建了一个带导航栏的母版页。我将索引页面作为登录页面,因此我使用在主页面下注册的index.aspx中的登录控件。
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
现在我的问题是如何在用户登录之前隐藏主页中的导航栏,用户成功登录后导航栏应该出现
4 个解决方案
#1
7
Use this in the Master Page (C# code)
在母版页中使用它(C#代码)
<% if (HttpContext.Current.User.Identity.IsAuthenticated ) { %>
<div>navigation html when is authenticated</div>
<% } else { %>
<div>navigation html when is NOT authenticated</div>
<% } %>
#2
3
In webforms you can use the LoginView control to display different content depending on the user's authentication status:
在webforms中,您可以使用LoginView控件根据用户的身份验证状态显示不同的内容:
<asp:LoginView ID="LoginView1" Runat="server">
<LoggedInTemplate>
<div>Navigation Bar</div>
</LoggedInTemplate>
<AnonymousTemplate>
<div>Unauthenticated content</div>
</AnonymousTemplate>
</asp:LoginView>
#3
3
protected void Page_Load(object sender, EventArgs e)
{
String path = HttpContext.Current.Request.Url.AbsolutePath;
if (path == "/login.aspx")
{
Menu1.Visible = false;
}
}
#4
1
If you are using the Asp.net menu control, put the following code in page load:
如果您使用的是Asp.net菜单控件,请在页面加载中输入以下代码:
protected void Page_Load(object sender, EventArgs e)
{
Menu1.Visible = User.Identity.IsAuthenticated;
}
Otherwise put your navigation bar in a placeholder and show/hide the placeholder.
否则,将导航栏放在占位符中并显示/隐藏占位符。
#1
7
Use this in the Master Page (C# code)
在母版页中使用它(C#代码)
<% if (HttpContext.Current.User.Identity.IsAuthenticated ) { %>
<div>navigation html when is authenticated</div>
<% } else { %>
<div>navigation html when is NOT authenticated</div>
<% } %>
#2
3
In webforms you can use the LoginView control to display different content depending on the user's authentication status:
在webforms中,您可以使用LoginView控件根据用户的身份验证状态显示不同的内容:
<asp:LoginView ID="LoginView1" Runat="server">
<LoggedInTemplate>
<div>Navigation Bar</div>
</LoggedInTemplate>
<AnonymousTemplate>
<div>Unauthenticated content</div>
</AnonymousTemplate>
</asp:LoginView>
#3
3
protected void Page_Load(object sender, EventArgs e)
{
String path = HttpContext.Current.Request.Url.AbsolutePath;
if (path == "/login.aspx")
{
Menu1.Visible = false;
}
}
#4
1
If you are using the Asp.net menu control, put the following code in page load:
如果您使用的是Asp.net菜单控件,请在页面加载中输入以下代码:
protected void Page_Load(object sender, EventArgs e)
{
Menu1.Visible = User.Identity.IsAuthenticated;
}
Otherwise put your navigation bar in a placeholder and show/hide the placeholder.
否则,将导航栏放在占位符中并显示/隐藏占位符。