Purpose
This tutorial demonstrates Oracle Providers for ASP.NET usage and how tightly the providers integrate with existing ASP.NET management tools, controls, and services.
Overview
Overview
Oracle Providers for ASP.NET integrates directly with Microsoft ASP.NET controls and services to provide state management capabilities for web sites. State management is critical for managing persistent data, such as user information, user roles, and session information.
This tutorial builds upon the "Building ASP.NET Web Applications with Oracle Developer Tools for Visual Studio" tutorial. In that tutorial, you created a data grid retrieving employee information. In this tutorial, you now want to secure this employee data to ensure only authorized users can view the data. To accomplish this task, you will create an ASP.NET web user using the Oracle Membership Provider and test the web site's authentication with the provider with valid and invalid credentials.
Prerequisites
Prerequisites
Before starting this tutorial, you should:
1 . | Install Microsoft Visual Studio 2010 |
---|---|
2 . | Install Oracle Database 9.2 or later or Oracle Database XE |
3 . | Install Oracle 11g Oracle Data Access Components (ODAC) with Oracle Developer Tools for Visual Studio version 11.2.0.1.2 or later from OTN |
4 . | Complete the "Building ASP.NET Web Applications With Oracle Developer Tools for Visual Studio" OBE |
Enabling Oracle Providers for ASP.NET and Creating a Web User
In this section, you will use the ASP.NET Web Site Administration Tool to direct the web site to use the Oracle ASP.NET providers and create a new web user specific to this web site to demonstrate authentication features. Perform the following steps:
1 . | Reopen the website you created in "Building ASP.NET Web Applications With Oracle Developer Tools for Visual Studio" |
---|---|
2 . | Select View > Solution Explorer Under the root website node double click on Web.config |
3 . | In the Web.config file, select all the tags from the <membership> tag to the </roleManager> closing tag and click the Delete key to delete all the selected tags. Note: By default, these web.config entries have been pre-populated to use SQL Server ASP.NET providers. By deleting these entries, we can now configure them to use Oracle's ASP.NET providers. |
4 . | Select Website > ASP.NET Configuration. |
5 . | The ASP.NET Web Site Administration Tool appears in a browser window. Select the Provider tab. |
6 . | On the Provider page, select the second link: Select a different provider for each feature (advanced). |
7 . | When the Provider page reappears, change the Membership Provider to OracleMembershipProvider and Role Provider to OracleRoleProvider and select the Security tab. |
8 . | Under Users section in the Security tab, click Select authentication type. By default, the ASP.NET site uses Windows authentication to identify users. You are building a web site that will identify users by their site-specific logins and passwords. Therefore, the site must be configured to expect to use logins and passwords. |
9 . | Select From the internet and click Done. |
10 . | Select Create user. |
11 . | In the Create User section, enter your name and a password that contains at least 7 characters, including one non-alphanumeric character. Enter your email, and a security question and answer, then click Create User. |
12 . | The user account has been created. Click the Security tab. Note: If you click Continue, you will be allowed to enter another user. |
13 . | Note that there is now one existing user. Under Access Rules, select Manage access rules. |
14 . | Select Add new access rule. |
15 . | Select Anonymous users and Deny, then click OK. By default, anonymous access to the web site is enabled. The above settings secure the web site by disabling anonymous access. Now, only authenticated users can view the employee data. |
16 . | The access rule was created successfully. The web site will now deny anonymous users access to the site. ClickDone. |
17 . | Close the browser. |
Testing Web Site Authentication
Now that you have created a web user specific to this web site, the web site will allow this user access to the employee data and deny access to all other users, including anonymous users. In this section, you will attempt to access the employee data as an anonymous user, as an unauthorized user, as an authorized user with an incorrect password, and finally as an authorized user with the correct password. Only in the last scenario will the web site grant access to the employee data. Perform the following steps:
Note: Five or more consecutive invalid passwords entered for an ASP.NET provider user within a ten minute period will lock the account to prevent unauthorized users from gaining access through password guessing. Oracle Membership Provider sets these security measures through the following properties, which you can modify in the machine.config file or web.config files: MaxInvalidPasswordAttempts (default: 5 attempts) and PasswordAttemptWindow (default: 10 minutes). If the account is locked, then you can unlock the user by calling the UnlockUser method.
1 . | Switch to Visual Studio. A message box will pop up stating that web.config has changed. Select "Yes" to accept the changes. |
---|---|
2 . | Examine the Web.config in the editor. Note that several entries for Oracle providers have been added. These provider values simply default to entries that were added earlier to the machine.config by the Oracle installer. Note: If you wanted to configure the Oracle providers differently for each separate web site, (for example, changing password length requirements for the membership provider) you could copy the entries from the Machine.config into the Web.config. |
3 . | Select Debug > Start Without Debugging. |
4 . | The login web page appears. |
5 . | Enter some other username and password which is different than the user you created earlier in the ASP.NET Web Site Administration Tool. Then click Log In. |
6 . | Notice that you receive an error indicating that the user you entered is not valid. The web site correctly denies access to the user. |
7 . | Enter the user name you entered in the in the ASP.NET Web Site Administration Tool but with an incorrect password for that web site user. Click Log In. As the screen shot indicates, the user is denied access, demonstrating that the control could not verify this user's credentials with those stored by the Oracle Membership Provider. |
8 . | Enter the correct username and password for the web site user. Click Log In. The employee data appears. This demonstrates that only authorized users can access the data. Thus, Oracle Providers for ASP.NET provided web site security in a very simple manner. You have now built a data-driven ASP.NET web application. It performs authentication and retrieves employee data from the database. |