Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Controls - Using Membership & User Login controls in ASP.NET 2.0
Using Membership & User Login controls in ASP.NET 2.0


ASP.NET Controls Tutorial

This tutorial will show how you can set up membership and user login for a website using ASP.NET 2.0

In Visual Studio, Website > ASP.NET Configuration will take us to the Web Site Administration Tool. We need to go on the Security tab and then choose 'Use the security Setup Wizard to configure security step by step'. We will choose the options 'From the Internet', but do not need to Enable Roles for this tutorial. Choose a username, password, email and security question & answer.
Back on the Security page, chose Create Access Rules. Click on the page/directory you want to restrict access to and choose 'Anonymous Users' and 'Deny'. Then click Ok.
In order to email when a new user has been created, you can set up the SMTP server details in the Administration Tool.

I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.

From the Toolbox, you'll notice there is a whole section dedicated to Login features. You can use the LoginStatus to show whether a user is logged in or not (and provide a link to log in or log out).
The Login control will let a user log in to the website with their username and password.
We can also use a Validation Summary control and set its ValidationGroup to the ID of the Login control.
The LoginView control will let you specify content viewable by both logged in members and anonymous users.
We can use the LoginName control to output the username of the currently logged in user.
If we create a page in the directory that we have set an access rule for, anonymous users will not be allowed to view them. Instead, they will be asked to log in.

We can add a CreateUserWizard control to allow users to register themselves.
We can also let users change their own password with the ChangePassword control.
You can also add a PasswordRecovery control, but must have SMTP server settings correctly configured in the Adminitration Tool.

So with the above controls implemented, no code has been written, and yet we have a multi-function log-in system on our website.
Here is what the homepage should look like:
<form id="form1" runat="server">
<div>
<h1>Welcome to the website.<br /></h1>
<br />
<asp:LoginStatus ID="LoginStatus1" runat="server" /> -
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/MemberPages/Members.aspx">Goto Members Only Page</asp:HyperLink><br />
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
You are logged in. Welcome,
<asp:LoginName ID="LoginName1" runat="server" />
.
</LoggedInTemplate>
<AnonymousTemplate>
You are not logged in, please click the link above to log in.
Or, please
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/Register.aspx">Register</asp:HyperLink>
</AnonymousTemplate>
</asp:LoginView>
</div>
</form>

We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.

The Login page should look something like this:

<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333">
<TitleTextStyle BackColor="#507CD1" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
</asp:Login>
<br />
&nbsp;<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="Login1" />

</div>
</form>

Try Server Intellect for Windows Server Hosting. Quality and Quantity!

Register.aspx:

<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Home
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderStyle="Solid" BorderWidth="1px" ContinueDestinationPageUrl="~/Default.aspx" Font-Names="Verdana" Font-Size="0.8em">
<WizardSteps>
<asp:CreateUserWizardStep runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
<SideBarStyle BackColor="#507CD1" Font-Size="0.9em" VerticalAlign="Top" />
<TitleTextStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<SideBarButtonStyle BackColor="#507CD1" Font-Names="Verdana" ForeColor="White" />
<NavigationButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284E98" />
<HeaderStyle BackColor="#284E98" BorderColor="#EFF3FB" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="White" HorizontalAlign="Center" />
<CreateUserButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284E98" />
<ContinueButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284E98" />
<StepStyle Font-Size="0.8em" />
</asp:CreateUserWizard>
<br />
</div>
</form>

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

MembersPages/ChangePassword.aspx:

<form id="form1" runat="server">
<div>
&nbsp;<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Home</asp:HyperLink>
<asp:ChangePassword ID="ChangePassword1" runat="server" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" ContinueDestinationPageUrl="~/Default.aspx" Font-Names="Verdana" Font-Size="0.8em">
<CancelButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<PasswordHintStyle Font-Italic="True" ForeColor="#507CD1" />
<ChangePasswordButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
<ContinueButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
<TitleTextStyle BackColor="#507CD1" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
<TextBoxStyle Font-Size="0.8em" />
</asp:ChangePassword>
</div>
</form>

MemberPages/Members.aspx:

<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Home</asp:HyperLink> -
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/MemberPages/ChangePassword.aspx">Change Password</asp:HyperLink>
<br />
Welcome members ! This page is viewable only by logged in users.
</div>
</form>

Download the Full Working Version of this Project written with Visual Studio.NET 2005 Here!

Looking for more ASP.NET Tutorials? Click Here!







 
  Developer Resources







Server Intellect Rocks