Overview: Building an ASP.NET Application with Oracle Developer Tools
Oracle integrates directly with Microsoft ASP.NET in a number of ways:
Oracle Developer Tools for Visual Studio provides an easy way to design data-driven web sites.
ODP.NET enables ASP.NET data access.
Oracle Providers for ASP.NET integrate directly with Microsoft ASP.NET controls and services to provide state management capabilities for web sites.
This tutorial demonstrates some of these features, including how to build a data-driven web application using Oracle Developer Tools and how to add security to that application in a simple manner using Oracle Providers for ASP.NET.
First, you will use the tools to build a web application that retrieves employee data from the Oracle database into a data grid. Then, you add a login control and secure the application by permitting only authorized web users access to this employee information. Finally, you create authorized web users using Oracle Providers for ASP.NET. These web users are stored within the Oracle database for authentication by this application.
Before Beginning This Tutorial
Before you can build an ASP.NET application with Oracle Developer Tools, you may need to perform the setups described in the following sections:
Creating a Web Site and Connecting it to the Database
This section shows you how to create an ASP.NET web site that retrieves data from an Oracle database. The web site will display data in an ASP.NET GridView, allowing users to page through the results.
From the GridView Tasks, select Enable Paging. If you do not see the task list, select the grid, and then click the > symbol on the right. You may have to scroll right.
From the View menu, select Solution Explorer, and then select the web site. Right-click and select Build Web Site. The status bar will indicate success or failure.
From the View menu, select Debug, then Start Without Debugging.
A browser window, such as the following, appears, showing the data requested by the query. You can page through the results using the numbers at the lower left section of the page.
This section shows you how to add web site authentication to limit the users that can access the employee data. We will authenticate using an ASP.NET login control, verifying against users created and stored with the Oracle Providers for ASP.NET.
In the section following this, "Enabling Oracle Providers for ASP.NET and Creating a Lightweight Web User", you will take the ASP.NET application you have just built and secure the employee data so that an authorized user can access the information. You will create a web user for the application using Oracle Providers for ASP.NET. This web user starts the web application through the login control, and if the credentials are correct, can then access the employees information.
Reopen the web site you created in the previous section.
Select View, then Solution Explorer, and click the web site.
When the login.aspx page appears, switch to the Design tab.
From the View menu, open the Toolbox, expand the Login section, and drag and drop the login control onto the form, into the dotted rectangle labeled <div>.
This is a standard ASP.NET login control, which can retrieve and verify user login credentials stored in the Oracle database.
Right-click the login control and select Properties. For DestinationPageUrl, select or enter Default.aspx.
When a user successfully logs in, that user will be directed to the Default.aspx page, which contains the employee data. If a user does not successfully log in, they will be redirected back to the login page.
Go to the Security tab and under Users, 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.
In the Create User section, enter the information for the user that you are allowing to enter the web site, as shown. Enter a password that contains at least 7 characters, including one non-alphanumeric character.
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.
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.
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.
From the Debug menu, select Start Without Debugging, and when the login web page appears, change the URL to end with Default.aspx rather than login.aspx and press the enter key.
You are denied access and redirected back to the login page. This shows that anonymous users cannot browse the web site; only users with credentials have access.
If you are experimenting with the authentication mechanism, you will likely repeat this step or try variations. For each variation, either start a new browser or clear the browser cache. Because browsers cache web pages, if you access Default.aspx again, you may see the cached version of this web page. This is not the intended behavior, rather the web page should undergo the ASP.NET provider authentication process, which is accomplished by using a new browser instance or clearing the browser cache.
Remove the text of the URL after login.aspx. This returns the URL back to the original state when you first accessed the site.
Enter the User Name Bob and a password that contains at least 7 characters, one of which is non-alphanumeric.
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.
Enter the correct 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.