ACC97: How to Use ASP Files to Query a Secure MS Access DatabaseLast reviewed: September 8, 1997Article ID: Q163159 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. WARNING: Although this article discusses Microsoft Access security features, any information you send over the Internet with the techniques described in this article is sent unencrypted. To send encrypted information over the Internet, you must use a protocol that sends client certificates, such as Secure Sockets Layer (SSL). Note that client certificates cannot be used on Personal Web Server for Windows 95. ANY USE BY YOU OF THE METHODS PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this sample "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This article describes a technique you can use to create Active Server Pages (ASP) files that allow you to type a username and password in an HTML form in order to query a secure Microsoft Access database. This article describes how to use the technique when exporting a query and when exporting a form.
MORE INFORMATIONThere are three main steps to using ASP files to query a secure Microsoft Access database:
NOTE: The following example assumes that you are familiar with Microsoft Access security and will require you to create a secured copy of the Northwind sample database shipped with Microsoft Access. This example contains the following sections:
Creating a System DSN for a Secure Microsoft Access Database
Creating the ASP Files and the HTML Logon FormIn this section, you create a query with username and password parameters, and then export the query to ASP format. When you create ASP files from a parameter query, Microsoft Access automatically creates an HTML form for entering the parameters. This is an easy way to create the HTML form you need to collect the username and password information. However, you do not have to use this technique to create the HTML form; you can use Notepad or another tool, such as Microsoft Front Page 97, to create your own HTML Logon form. NOTE: Username and password information needs to be supplied by either the System DSN or by the IDC file itself when accessing databases that have been secured by changing the permissions of objects. An interesting feature to note is that if a database has been secured with a database password rather than object permissions, the password information supplied by the System DSN or by the IDC file will still be used to gain authorization into the database even though the password has nothing to do with a user account in a system database.
1. Start Microsoft Access. 2. Open Northwind2.mdb. 3. Create the following new query called GetUserPass based on the Customers table: Query: GetUserPass ------------------ Type: Select Query Field: CustomerID Table: Customers 4. On the Query menu, click Parameters. 5. Type the following in the Query Parameters dialog box, and then click OK. Parameter Data Type ---------------------------- [UserParam] Text [PassParam] Text 6. Save the GetUserPass query and close it. 7. On the File menu, click Save as HTML. The "Publish to the Web Wizard" dialog box opens. Click Next. 8. Click the Queries tab, and select the GetUserPass query. Click the Forms tab, and select the Customers form. Click Next, and Next again. 9. You will be asked to select a format type to create. Select Dynamic ASP (Microsoft Active Server Pages). Click Next. 10. In the Data Source Name box, enter NorthwindASP, and click Next. 11. The Publish Objects Locally button should be selected. Note the folder where the ASP files will be exported to. You do not need to make any more selections, so you can click Finish at this point. 12. Click OK in each of the two Enter Parameter Value dialog boxes that appear. 13. The ASP output creates four files: GetUserPass_1.asp, GetUserPass_1.HTML, Customers_1.asp, and Customers_1alx.asp. Customizing the ASP Files and the HTML formNOTE: This section contains information about editing ASP and HTML files, and assumes that you are familiar with editing HTML files, Active Server, and Visual Basic Scripting. Microsoft Technical Support engineers do not support customization of any HTML, HTX, IDC, or ASP files.
1. Use Notepad or another text editor to open the GetUserPass_1.asp file. At the top of the file, you will see the following code: <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=windows- 1252"> <TITLE>GetUserPass</TITLE> </HEAD> <BODY> <% Param = Request.QueryString("Param") Data = Request.QueryString("Data") %> <% If IsObject(Session("NorthwindASP_conn")) Then Set conn = Session("NorthwindASP_conn") Else Set conn = Server.CreateObject("ADODB.Connection") conn.open "NorthwindASP","","" Set Session("NorthwindASP_conn") = conn End If %> Replace the above code with the following (the rest of the code should remain the same): <% If IsObject(Session("NorthwindASP_conn")) Then Set conn = Session("NorthwindASP_conn") Else If Request.Form("[UserParam]") = "" then response.redirect "GetUserPass_1.HTML" Else Set conn = Server.CreateObject("ADODB.Connection") conn.open "NorthwindASP", Request.Form("[UserParam]"), _ Request.Form("[PassParam]") Set Session("NorthwindASP_conn") = conn End If End If %> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=windows- 1252"> <TITLE>GetUserPass</TITLE> </HEAD> <BODY> 2. Save the GetUserPass_1.asp file and close it. 3. Use Notepad or another text editor to open the Customers_1.asp file. At the top of the file you will see the following code: <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=windows- 1252"> <TITLE>Customers</TITLE> </HEAD> <BODY> <% If IsObject(Session("NorthwindASP_conn")) Then Set conn = Session("NorthwindASP_conn") Else Set conn = Server.CreateObject("ADODB.Connection") conn.open "NorthwindASP","","" Set Session("NorthwindASP_conn") = conn End If %> Replace the above code with the following (the rest of the code should remain the same): <% If IsObject(Session("NorthwindASP_conn")) Then Set conn = Session("NorthwindASP_conn") Else If Request.Form("[UserParam]") = "" then response.redirect "GetUserPass_2.HTML" Else Set conn = Server.CreateObject("ADODB.Connection") conn.open "NorthwindASP", Request.Form("[UserParam]"), _ Request.Form("[PassParam]") Set Session("NorthwindASP_conn") = conn End If End If %> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=windows- 1252"> <TITLE>Customers</TITLE> </HEAD> <BODY> Save the Customers_1.asp file and close it. These changes will make the ASP file use the HTML form to request a username and password if the user had not yet entered a username and password for the session. 4. Use Notepad or another text editor to open the GetUserPass_1.HTML file. By default, the HTML form uses the GET method to submit its data. Get variables appear in the address box of Web browsers. Therefore, you must change the GET method to the POST method if you do not want your password to be visible in the address box of your Web browser. Locate the following line in the GetUserPass_1.HTML file <FORM METHOD="GET" ACTION="GetUserPass_1.asp"> and change it to: <FORM METHOD="POST" ACTION="GetUserPass_1.asp"> 5. Text boxes use an Input Type setting of Text by default. In order to prevent your password from being visible in the text box on your form, you must change the Input Type to Password. Locate the following line in the GetUserPass_1.HTML file [PassParam] <INPUT TYPE="Text" NAME="[PassParam]"><P> and change it to: [PassParam] <INPUT TYPE="Password" NAME="[PassParam]"><P> 6. In Notepad, on the File menu, click Save. You will need to create another HTML form so do not close Notepad. 7. In Notepad, on the File menu, click Save As. 8. In the File Name box, type GetUserPass_2.HTML. 9. In the Save As Type box, select All Files, and click Save. 10. Locate the following line in the GetUserPass_2.HTML file <FORM METHOD="POST" ACTION="GetUserPass_1.asp"> and change it to: <FORM METHOD="POST" ACTION="Customers_1.asp"> 11. On the File menu, click Save. On the File menu, click Exit. 12. Copy GetUserPass_1.HTML, GetUserPass_2.HTML, GetUserPass_1.asp, Customers_1.asp, and Customers_1alx.asp to a folder on your Web Server computer where you have both Read and Execute permission. For more information about configuring Microsoft Internet Information Server (IIS) permissions, please refer to the IIS Help Index, and see the following article in the Microsoft Knowledge Base: ARTICLE-ID: Q160754 TITLE : Error "HTTP/1.0 403 Access Forbidden" Browsing IDC Page Testing the Query
REFERENCESFor more information about how to create and modify ASP files, please refer to your Microsoft ASP online documentation. For more information about IIS authentication, security, and Secure Sockets Layer (SSL), please refer to your IIS online documentation, or see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q142868 TITLE : IIS: Authentication & Security FeaturesFor more information about Microsoft Access security, search the Help Index for "security, overview," or ask the Microsoft Access 97 Office Assistant.
|
Additional query words: internet intranet iis pws peer web services
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |