BIS 450 DeVry Week 6 I Lab 7
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
STEP 2: Modify Web.config File.<br />
1. Open the Web.config file for the Healthy Eating site.<br />
2. Open the <strong>BIS</strong><strong>450</strong> <strong>Lab</strong>6 Code Snippets.txt file that you downloaded from Doc Sharing. Select and copy the block of<br />
XML code that begins with the tag and ends with . Paste this block of code into the Web.config file immediately before<br />
the tag, as shown:<br />
TIP: In this case, there is only one user who will be logging into the site (the administrator who will maintain the Healthy<br />
Eating database). Other visitors don’t need to log in. We will store the log-in name and password for this user in the<br />
Web.config file, because that’s the simplest solution for a single log-in. For a site with a large number of users, each<br />
with their own username and password, log-in information would most likely be stored in a database table.<br />
3. Save the modified Web.config file.<br />
STEP 3: Create Log-In Form.<br />
1. In the Solution Explorer window, click on the website root (ftp://bisweb.devry.edu/coursefolder/yourname) to select<br />
it; then add a new Web form named Login.aspx to the site.<br />
2. Set the Title property of the Document to Healthy Eating Login.<br />
3. Attach StyleSheet.css to the Web form.<br />
4. As you did when setting up the Web forms in the previous labs, open Default.htm and copy the contents of its element<br />
(in HTML, everything in between the and tags, but not the and tags themselves). Paste these contents inside the div in<br />
Login.aspx (in HTML, in between the<br />
and<br />
tags). Delete the contents of the #main div after pasting.<br />
5. Drag a Login control from the Login section of the Toolbox and drop it onto the form inside div#main. Click Auto<br />
Format on the Login control’s smart tag, select the Classic scheme, and click OK. In the Properties window, set the<br />
DisplayRememberMe property of the Login control to False. Your form should now look like the following:<br />
6. Save the Login.aspx form.<br />
STEP 4: Add Code to Authenticate and Redirect User.<br />
1. Double-click the Login control to create a skeleton event handler for the control’s Authenticate event in the codebehind<br />
file for the form. This procedure will be executed whenever a user tries to log in, to determine if he or she is a<br />
valid user.<br />
2. In the <strong>BIS</strong><strong>450</strong> <strong>Lab</strong>6 Code Snippets.txt file that you downloaded from Doc Sharing, select and copy the block of VB<br />
code that begins with the comment, “‘Authenticate user against credentials in Web.config”. Paste this code into the<br />
Login1_Authenticate event handler procedure, in between the Protected Sub Login1_Authenticate(. . . ) and the End<br />
Sub statements, as shown:<br />
TIP: If log-in credentials were stored in a database table, this code would need to execute a SQL query to see if a<br />
record with the username and password exists, instead of comparing the username and password with the values from<br />
the Web.config file. Otherwise, the log-in process would be the same.<br />
3. Now that the user is authenticated, you need to add code to redirect the user to the correct page following a<br />
successful log-in. At the top of the editing window, select Login1 in the left drop-down list (if not already selected) and<br />
select LoggedIn from the right drop-down list. This will create a skeleton event handler procedure for the LoggedIn<br />
event, which fires after a successful log-in:<br />
4. In the <strong>BIS</strong><strong>450</strong> <strong>Lab</strong>6 Code Snippets.txt file that you downloaded from Doc Sharing, select and copy the block of VB<br />
code that begins with the comment, “‘Save user name in session state and redirect user”. Paste this into the LoggedIn<br />
event handler, in between the Protected Sub Login1_LoggedIn(. . .) and End Sub” statements:<br />
TIP: This code does two things:<br />
a. It stores the username in a session variable so that other forms can determine whether the user is logged in; and<br />
b. it sends the user to a different page following a successful log-in.