ASP.NET 3.5: Creating Role Based Security with User Login Pages

Creating user login controls helps to maintain the security of your website. This article will show you how to create them using ASP.NET. It is part of a series on securing your ASP.NET-based website by using role-based security.

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 32
August 23, 2010
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

This is the third part of a series on ASP.NET 3.5 role-based security and user authentication web development. In the second part, you created important ASP.NET pages that are vital part of the website functionality.

In this part, we'll start dealing with ASP.NET login controls.

Creation of CreateNewUser.aspx

The path of this page is this: /aspnetloginexercise/CreateNewUser.aspx. Its main purpose is to serve as the registration page for new workers. Way back in the first part, we included only three registered workers, namely Peter, John and Mary.

To add more workers for the company, you need a registration page, which is CreateNewUser.aspx. To do this, follow the steps below:

Step 1. Launch the aspnetloginexercise in Visual Web Developer.

Step 2. Create a new ASP.NET page at the root of your website and name it CreateNewUser.aspx.

Step 3. Go to File -> Save All.

CreateNewUser.aspx should be located like this in your Solution Explorer:

Step 4. Now you need to add a CreateUserWizard web control to the CreateNewUser.aspx. Go to the source code of CreateNewUser.aspx, and then click and drag CreateUserWizard (Toolbox -> Login -> CreateUserWizard) to between <form><div> and </div></form> tags.

Step 5. Go to the Design View. Let's add some relevant text. Press enter at the top of the CreateUserWizard web control to enter this text (no quotes):

"Instructions for new workers: Enter as completely as possible when signing up as new worker"

Step 6. Go to File -Save all.

The CreateNewUser.aspx should then look like the screen shot below in the Design View:


Creation of ThankYou.aspx

You can, if you wish, create a thank you page (also called a success URL) that appears after registration. Although this is not part of the original design, it can be important as part of the new worker registration process. Seeing this page informs them that the administrator will still need to review their application before it is marked active. To create ThankYou.aspx:

Step 1. Add a new page at the root of your website (with the same path as the CreateNewUser.aspx page) and named it ThankYou.aspx.

Step 2. Go to the source code view of ThankYou.aspx. Let's add some relevant text to it. Place this text somewhere between the <form><div> and </div></form> tags. This is the text (without quotes):

"Thank you for registering as new worker of this company. Your application is still inactive, so the administrator will still review your application. If it is OK, it will be marked active, and then you can start logging in to this website."

Step 3. Assign a title tag to ThankYou.aspx (at the source code view):

<title>Thank you for registering as new worker</title>

Step 4. Go to File -> Save All. Go to the Design view of ThankYou.aspx. It should look like this:

Configure the CreateUserWizard Web Control

Go to the Design View of CreateNewUser.aspx. Click the CreateUserWizard web control to see the CreateuserWizard1 properties at the bottom left of Design View.

Follow the rest of the configuration steps:

1. Under Properties, go to "Behavior" and then click "ContinueDestinationPageUrl."

2. Click the Ellipsis (...).

3. Under "Select URL" dialog, select "ThankYou.aspx" under "Contents of folder."

4. Click OK.

5. Go to File -> Save All.

It should look like the screen shot below:

To configure newly registered workers as "inactive" by default:

1. In the Design view of CreateNewuser.aspx, click the CreateUserWizard web control to view the Properties window in the bottom right.

2. Go to Behavior and find DisableCreatedUser. The default setting is "False." This means that the newly registered workers are active by default and can immediately log in to the website.

3. To make newly registered workers "inactive" by default, change the value of DisableCreatedUser from "False" to "True."

4. Go to File -> Save All.

Adding the Navigation Menu to the Website

A website requires a consistent and clear navigation menu. Let's add a navigation menu to all of the pages of the website, so that at any point, visitors can turn back or visit the pages they need to see.

The following pages should be included in your navigation menu:

  • Home page - /aspnetloginexercise/Default.aspx
  • Register New workers - /aspnetloginexercise/CreateNewUser.aspx
  • View tasks - /aspnetloginexercise/registeredworkers/Viewtasks.aspx
  • Login - /aspnetloginexercise/login.aspx
  • Assign tasks - /aspnetloginexercise/administrator/assigntasks.aspx
  • Edit tasks - /aspnetloginexercise/administrator/edittasks.aspx
  • Thank you page - /aspnetloginexercise/ThankYou.aspx

Using relative URLs in hyperlinks, the following is the complete navigation menu source code:

<br /><br />
<b>Website Navigation :</b><br />
<br />
<asp:LoginStatus ID="LoginStatus1" runat="server" />
<br />
<a href="/aspnetloginexercise/Default.aspx">Homepage</a>
<br />
<a href="/aspnetloginexercise/CreateNewUser.aspx">Register New Workers</a>
<br />  
<a href="/aspnetloginexercise/registeredworkers/Viewtasks.aspx">View tasks</a>
<br />
<a href="/aspnetloginexercise/administrator/assigntasks.aspx">Assign tasks</a>
<br />
<a href="/aspnetloginexercise/administrator/edittasks.aspx">Edit tasks</a>
<br />

Now let's take a look at what the code does. The login web control code: <asp:LoginStatus ID="LoginStatus1" runat="server" /> has been thoroughly discussed in this tutorial: http://www.aspfree.com/c/a/.NET/Creating-ASPNET-Login-Web-Pages-and-Basic-Configuration-/3/

The purpose of that is to present a login link when the user is not logged in; otherwise, a "logout" link will be presented. When a user clicks the login link, he or she will be directed to login.aspx.

In addition, the "thank you" page (ThankYou.aspx) is not included in the hyperlink code because it is not an important page. However, navigation is placed on ThankYou.aspx pointing to other pages of the website, because after successful user registration, they might click a link back to the home page or other website pages.

So how do we add the above navigation menu source code?

Step 1. Go to the source code view of each of these ASP.NET pages in Visual Web Developer:

/aspnetloginexercise/Default.aspx

/aspnetloginexercise/CreateNewUser.aspx

/aspnetloginexercise/registeredworkers/Viewtasks.aspx

/aspnetloginexercise/login.aspx

/aspnetloginexercise/administrator/assigntasks.aspx

/aspnetloginexercise/administrator/edittasks.aspx

Step 2. Copy and paste the above navigation menu source code between </div> and </form>

For example, this is the complete Default.aspx source (with some added relevant text for the home page in addition to the website navigation):

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Hi <asp:LoginName ID="LoginName1" runat="server" />, welcome to Codex Online Corporation. If you are logged in to the website, you will see the logout link below, otherwise a login link will be shown. If you are worker of this corporation, you need to login in order to view your tasks. Take note that you will not be able to view some of the administrative pages of this website as they are viewable only by your supervisor or administrator.<br /><br /> If you are a new worker, it is encourage you will register to this website
        to view the tasks assigned to you. Also bear in mind that you will not be able to login right away as the administrator still needs to mark your account active.
        Thank you for visiting this website!<br />
    <br />
    </div>

<b>Website Navigation:</b><br />
<br />
<asp:LoginStatus ID="LoginStatus1" runat="server" />
<br />
<a href="/aspnetloginexercise/Default.aspx">Homepage</a>
<br />
<a href="/aspnetloginexercise/CreateNewUser.aspx">Register New Workers</a>
<br />  
<a href="/aspnetloginexercise/registeredworkers/Viewtasks.aspx">View tasks</a>
<br />
<a href="/aspnetloginexercise/administrator/assigntasks.aspx">Assign tasks</a>
<br />
<a href="/aspnetloginexercise/administrator/edittasks.aspx">Edit tasks</a>
<br />   
    </form>
</body>
</html>

Screen shots of Completed ASP.NET pages in Design View

All of the required ASP.NET pages has been completed. Refer to the screen shots linked below to make sure your output in the Visual Web Developer Design view is similar to the ones provided:

Default.aspx

Assigntasks.aspx

CreateNewUser.aspx

Edittasks.aspx

Login.aspx

Thankyou.aspx

View tasks

In the next part, we'll configure the ASP.NET user role management to provide certain users access to some files and put some restriction on others.

blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials