Automatically Hiding the Login Control from Authenticated Users
Posted by Tihomir Ivanov on 14 October 2008 07:31
Rating: 0.00
Some websites display a login form at the top of every page. That way, registered users can
log in at any time to view additional content. The easiest way to add a Login control to all
the pages in an application is to take advantage of Master Pages. If you add a Login
control to a Master Page, then the Login control is included in every content page that
uses the Master Page.
You can change the layout of the Login control by modifying the Login control’s
Orientation property. If you set this property to the value Horizontal, then the Username
and Password text boxes are rendered in the same row.
If you include a Login control in all your pages, you should also modify the Login
control’s VisibleWhenLoggedIn property. If you set this property to the value False, then
the Login control is not displayed when a user has already authenticated.
Example:
in .master file:
<%@ Master Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
html
{
background-color:silver;
}
.content
{
margin:auto;
width:650px;
border:solid 1px black;
background-color:white;
padding:10px;
}
.login
{
font:10px Arial,Sans-Serif;
margin-left:auto;
}
.login input
{
font:10px Arial,Sans-Serif;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<asp:Login
id="Login1"
Orientation="Horizontal"
VisibleWhenLoggedIn="false"
DisplayRememberMe="false"
TitleText=""
CssClass="login"
runat="server" />
<hr />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
in aspx file:
<%@ Page Language="C#" MasterPageFile="~/MasterExample.Master" AutoEventWireup="true" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
Test Content
</asp:Content>

Comments:
No comments yet.