Home.NET ASP.NET 3.5 Role Based Security and User A...
ASP.NET 3.5 Role Based Security and User Authentication Web Development A Further Look
This is the seond part of a tutorial series on developing ASP.NET 3.5 websites that will implement user role based security and user authentication. In the first part, you read about the project background, registering users in the website administration tool, and creating the WorkAssignment MS SQL server database table for saving tasks. We'll continue fleshing out the application here by building some pages essential for the end users: the supervisor and the workers.
Contributed by Codex-M Rating: / 9 August 17, 2010
This series will start discussing the creation of different ASP.NET pages that are part of the web development project. For a detailed description of these ASP.NET pages, please refer to the Part 1 of this tutorial.
Creation of Assigntasks.aspx
Assigntasks.aspx's purpose is to enable the web administrator and task supervisor to enter new tasks for their workers.
The ASP.NET web control used to accomplish this job is the DetailsView web control. This web control is primarily used when inserting data into the database. For more details on this web control, you can refer to this tutorial.
To create Assigntasks.aspx, the path of this page should be in (discussed in first tutorial): /aspnetloginexercise/administrator/assigntasks.aspx
However, the website still does not have an "administrator" directory. So let's create this directory first. Go through the following steps.
1. In the Solution Explorer, right click your project's path (example: E:aspdotnetprojectsaspnetloginexercise) and click "New folder."
2. Set the name of the folder to administrator.
Now let's add Assigntasks.aspx under the Administrator folder:
1. Right click on the administrator folder and click "Add New Item."
2. Under "Visual Studio Installed Templates," select "Web form." Change the name of that page to Assigntasks.aspx and just leave everything else at the default settings (language= Visual Basic and checking "Place code in separate file").
3. Finally, click Add.
After following the steps above, your Solution Explorer should look like the screen shot below:
Go to the source code of Assigntasks.aspx. Since DetailsView is a database-driven web control, you need to add a SqlDataSource web control first.
1. Drag SqlDataSource (Toolbox -> Data -> SqlDataSource) to the Assigntasks.aspx source code between <form><div> and </form></div> tags.
2. Go to the Design View. To configure SqlDataSource, go through the following steps:
Right click on the web control -> Show Smart Tag -> Configure Data Source.
Under which Data Connection to connect, select ASPNETDB.MDF database, and click Next.
Check "Yes, save this connection as: ConnectionString."
Under "Specify columns from a table or view," select the "WorkAssignment" table.
Under Columns, check *.
Click "Advanced..."
Check "Generate INSERT, UPDATE, and DELETE statements." This is required since you are inserting records into the database in Assigntasks.aspx. Click OK.
Click Next.
Click Finish.
Now that we've finished configuring SqlDataSource, we need to go back to the design view.
3. In the Design View, click and drag the DetailsView web control (Toolbox -> Data -> DetailsView) below the SqlDataSource.
It should look like the screen shot below:
4. Now we need to configure the DetailsView web control.
Right click the DetailsView web control -> Show Smart Tag.
Under Choose Data Source, select "SqlDataSource1."
Check "Enable Inserting."
Now, under properties at your lower right, under "Behavior," change the DefaultMode to Insert.
Click the DetailsView web control again -> Show Smart Tag -> Edit Fields.
Under Available Fields, select "Tasks" and then click the link "Convert this field into a Template field."
Click OK.
Go to the Source Code view of Assigntasks.aspx and find this line of code:
The task supervisor also needs some way to edit and update tasks given to the workers. This is the purpose of Edittasks.aspx.
The path of this web page is: /aspnetloginexercise/administrator/edittasks.aspx. This is presented using an editable Gridview web control. The steps, which are similar to those in the previous section, are as follows:
1. Add a new ASP.NET page inside the administrator folder and name it Edittasks.aspx.
2. Add SqlDataSource control.
3. Configure the SqlDataSource in the Design View according to following specifications:
Data Connection: ConnectionString
Check "Specify Columns from a table or view." Name of the table: WorkAssignment
Columns: *
Click Advance and check "Generate INSERT, UPDATE and DELETE statements."
Click Next and Finish.
4. Click and drag the Gridview web control below SqlDataSource in Design.
5. Configure Gridview as follows:
Right click on it in Design View and click "Show Smart tag."
Viewtasks.aspx is located in the path: /aspnetloginexercise/registeredworkers/viewtasks.aspx
It is situated in the "registeredworkers" directory (to be created in this section). This is the ASP.NET web page where workers log in to see the tasks assigned to them by their supervisor.
This is not editable (unlike the administrator pages); it's for viewing purposes only. The following are the steps you'll take to create this page:
1. Create the registeredworkers folder in the same path as the administrator folder created earlier.
2. Add a new ASP.NET page inside the registeredworkers folder and name this page Viewtasks.aspx
3. Go to File -> Save All.
Your Solution Explorer should then look like this:
4. Go to the Source Code view, and click and drag SqlDataSource. (You want the same location as the previous section).
5. Configure SqlDataSource using the same procedure as we used in the previous section.
Data connection: ConnectionString
Check "Specify Columns from a table or view."
Name of table: WorkAssignment
Columns: *
Click Next and Finish.
Note that there is no editing of advanced SQL parameters, because you do not need to insert and update tasks in Viewtasks.aspx -- remember, it is only for viewing purposes.
6. Click and drag the Gridview web control below SqlDataSource in the Design view.
7. Right click on the Gridview web control, and then click Show Smart tag. Choose Data Source: SqlDataSource1
Please note that those pages are pulling data out of the database table you created in the first part, called the WorkAssignment table.
Do not yet add ant new tasks in Assigntasks.aspx or update/delete/edit any tasks in Edittasks.aspx. We'll continue in part three of this tutorial, which is where we'll start configuring the ASP.NET login controls.