创建受Access db上存储的凭据保护的网页

时间:2013-11-26 16:40:30

标签: asp.net ms-access

我已经尝试了很长一段时间在我的网站上设置一个受保护的页面,该页面只有拥有凭据的用户才能访问,我已将其存储在Access数据库中。我基本上遵循我在Microsoft支持上找到的结构。 不幸的是,我很难让连接字符串工作。我一直收到“无法找到提供商的错误。可能没有正确安装。”

基本上,我已经创建了一个Logon.asp文件,该文件收集用户凭据并将它们发送到另一个文件Validate.asp。此文件应连接到我的Access数据库,并检查凭据是否存在,从而允许/拒绝访问。

我在Validate.asp中编写的代码如下:

<%
Response.Buffer=true

'The following three lines of code are used to make sure that this page is not cached on the client.
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1

Dim userid
Dim Pwd
'Assign the user ID to this variable. The user provides the user ID.
userid= Request.Form("UID")
'Check whether userid is an empty string. If it is empty, redirect to Logon.asp.
'If it is not empty, connect to the database, and validate the user.

if userid <> "" then
    pwd = Request.Form("passwd")

    Dim Cn
    Dim Rs
    Dim StrConnect

'Specify the connection string to access the database.
'Remember to change the following connection string parameters to reflect the correct values
'for your SQL server.
Set Cn = Server.CreateObject("ADODB.Connection")
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("myaccessdb.accdb")
Set Rs = Server.CreateObject("ADODB.Recordset")
    Rs.Open "Select * from Users where uid='" & userid & "'",Cn
'Check to see whether this user ID exists in your database.
    If Not Rs.EOF then
        If strcomp( pwd, Rs.Fields("password").value , 1) = 0 then
'Password is correct. Set a session variable, and redirect the user to a Default.asp page
'or the main page in your application.
            Session("UID") = userid
            Response.Redirect "Default.asp"
            Response.End
        Else
'Password is incorrect. Redirect the user to the logon page.
            Response.Redirect "Logon.asp"
            Response.End
        End if
    Else
'If the user is not in your database, point him or her to the Register.asp page
'so that he or she can register at your Web site to access your application.
        Response.Redirect "Register.asp"
        Response.End
    End if
Else
    Response.Redirect "Logon.asp"
    Response.End
End if

%>

有关问题可能是什么的任何线索?

1 个答案:

答案 0 :(得分:2)

Microsoft.Jet.OLEDB.4.0无法读取.accdb个文件,因此您必须在服务器上安装Access Database Engine(ACE)可再发行组件(可用here),然后使用{ {1}}。

您需要为您的环境安装适当的版本:32位或64位。我的猜测是你需要64位,因为你的页面没有抱怨Microsoft.ACE.OLEDB.12.0文件是“无法识别的文件格式”,它说“找不到提供商”。 Jet OLEDB始终在32位空间中可用,并且在64位Universe中永远不可用,因此我猜测IIS正在64位环境中运行您的脚本。 (服务器的管理员将能够在安装ACE驱动程序之前验证它。)