ASP.Net 2005 provides a login control that creates a login form with a “remember me” cookie. The functionality to code ratio is huge:
Create two members (ctbogart, caroline) using the ASP.Net configuration icon on the top right of the solution explorer. Create two roles (Member, Admin). Assign ctbogart to the role Admin, caroline to the role Member.
Create two members (ctbogart, caroline) using the ASP.Net configuration icon on the top right of the solution explorer. Create two roles (Member, Admin). Assign ctbogart to the role Admin, caroline to the role Member.Create a web user control login.ascx. Add this tiny piece of code:
‹asp:login id=”login2″ runat=”server”›
Drag the control onto a web form. Run the project. Login. Wow.
Without a LoginView, the asp login control will display regardless of whether our user is logged in. It contains attributes to modify its appearance and abilities:
‹asp:Login ID=”login2″ runat=”server”
CreateUserText=”Create user”
CreateUserUrl=”create-new-user.aspx”
DisplayRememberMe=”true”
FailureAction=”RedirectToLoginPage”
FailureText=”Please try again”
InstructionText=”Enter your login and password”
LoginButtonText=”Click Here”
LoginButtonType=”link”
RememberMeSet=”true”
TextLayout=”textontop”
TitleText=”Hey You!”
UserName=”caroline”
UserNameRequiredErrorMessage=”Please enter your user name”
PasswordRequiredErrorMessage=”Please enter your password”
VisibleWhenLoggedIn=”false” /›
Conditional Login Display
A user can be anonymous or logged in. A logged in user can be in no role, one role, some roles or all roles. Our users are in the Member and Admin roles.
We can use the asp:Login code from above but I don’t yet know why there’s an align=right on the Click Here button link, so we’ll go back to the defaults.
The following code displays the login dialog when the user is logged off and a role-approriate message when the user is logged in:
‹asp:LoginView ID=”loginview2″ runat=”server”›
‹AnonymousTemplate›
‹asp:Login ID=”login3″ runat=”server”›‹/asp:Login›
‹/AnonymousTemplate›
‹LoggedInTemplate›
Hello, ‹asp:LoginName ID=”loginName1″ runat=”server”›‹/asp:LoginName›
‹/LoggedInTemplate›
‹RoleGroups›
‹asp:RoleGroup Roles=”Admin”›
‹ContentTemplate›
Hello, ‹asp:LoginName
ID=”loginName1″
runat=”server”›
‹/asp:LoginName›.‹br /›You are in role: Admin‹br /›
‹asp:LoginStatus ID=”LoginStatus1″ runat=”server”›‹/asp:LoginStatus›
‹/ContentTemplate›
‹/asp:RoleGroup›
‹asp:RoleGroup Roles=”Member”›
‹ContentTemplate›
Hello, ‹asp:LoginName
ID=”loginName1″
runat=”server”›
‹/asp:LoginName›. You are in role: Member‹br /›
‹asp:LoginStatus ID=”LoginStatus1″ runat=”server”›‹/asp:LoginStatus›
‹/ContentTemplate›
‹/asp:RoleGroup›
‹/RoleGroups›
‹/asp:LoginView›




{ 0 comments… add one now }
You must log in to post a comment.