用户登陆问题 .NET+ACCESS+C#
错误提示:Server Error in '/' Application.
--------------------------------------------------------------------------------
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type System.Web.UI.WebControls.Login from assembly System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
Source Error:
Line 11: <tr>
Line 12: <td height="52" align="center">
Line 13: <asp:Login ID="Login1" runat="server" BackColor="#F7F7DE"
Line 14: BorderColor="#CCCC99"
Line 15: BorderStyle="solid" BorderWidth="1px"
Source File: E:\aspx\Logon.aspx Line: 13
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2407; ASP.NET Version:1.1.4322.2407
文件web.config代码
__________________
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="data\BOOK.mdb"/>
</appSettings>
<system.web>
<compilation defaultLanguage="c#" debug="true"/>
<customErrors mode="Off"/>
<authentication mode="Windows"/>
<authorization>
<allow users="*"/>
</authorization>
<trace enabled="false" requestLimit="10"
pageOutput="false" traceMode="SortByTime"
localOnly="true"/>
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false" timeout="20"/>
<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
<pages validateRequest = "false"/>
</system.web>
</configuration>
logon.aspx
________________
<%Page Language="C#" AutoEventWireup="true" CodeFile="Logon.aspx.cs" Inherits="Logon" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login.axp</title>
</head>
<body>
<form id="form1" runat="server">
<table height="100%" cellSpacing="0" cellpadding="0" width="100%" border="0" >
<tr>
<td height="52" align="center">
<asp:Login ID="Login1" runat="server" BackColor="#F7F7DE"
BorderColor="#CCCC99"
BorderStyle="solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="10px" OnAuthenticate="OnAuthenticate">
<TitleTextStyle BackColor="#6B696B" Font-Bold="True"
ForeColor="#FFFFFF" />
</asp:Login>
<br/>
<a href="CreateUser.aspx">new user register</a>
</td>
</tr>
</form>
</body>
</html>
文件logon.aspx.cs代码
_____________
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Logon : System.Web.UI.Page
{
// 用户身份验证
public void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated=false;
Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName,Login1.Password);
e.Authentciated = Authenticated;
}
//在数据库中检验
private bool SiteSpecificAuthenticationMethod(stirng UserName, string password)
{
string strUserName, strPWD;//NAME KEY;
string strSql;//SQL
OleDbDataReader myReader;
strUserName = Login1.UserName;
strPWD = Login1.Password;
strSql = "select *from Users where userid='" + strUserName + "'";
clsDB dbo = new clsDB();
myReader = dbo.GetResultAsDataReader(strSql);
if(myReader.Read())
{//存在此用户
string strUserPwd=myReader["userpassword"].ToString();
if (strPWD == strUserPwd)
{// 密码正确
Response.Redirect("~/default.aspx");
myReader.Close();
myReader.Dispose();
dbo.killMe();
return true;
}
else
{
Login1.FailureText = "密码错误";
myReader.Close();
myReader.Dispose();
dbo.killMe();
return false;
}
}
else
{//用户不存在
Login1.FailureText="用户不存在";
myReader.Close();
myReader.Dispose();
dbo.killMe();
return false;
}
}
protected vodi Page_Load(object sender,EventArgs e)
{
}
}
文件App_Code/clsDB.cs代码
__________________
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public class clsDB
{
public OleDBConnection Conncetion;
public clsDB()
{
Connection = new OleDBConnection(connectionString());
Conncetion.Open();
}
private string connectionString()
{
return
System.Configuration.ConfigurationManger.AppSettings["ConnectionString"];
}
public OleDbDataReader GetResultAsDataReader(string strSql)
{
OleDbCommand command = new OleDbCommand(strSql, Connection);
if (Connection.State == ConnectionState.Closed)
Connection.Open();
return command.ExecuteReader();
}
public string ExecuteNoReturn(string strSql,string strTip)
{
string strReturn;
OleDbCommand myCommand=new OleDbCommand(strSql,Connection);
try
{
if(Connection.State==ConnectionState.Closed)
Connection.Open();
myCommand.ExecuteNonQuery();
strReturn=strTip+"succeed";
}
catch
{
strReturn=strTip+"false";
}
myCommand.Dispose();
Conneciton.Close();
return strReturn;
}
public void killMe()
{
Connection.Dispose();
}
}
--------------------编程问答-------------------- logon.aspx
________________
<%Page Language="C#" AutoEventWireup="true" CodeFile="Logon.aspx.cs" Inherits="Logon" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login.axp </title>
</head>
<body>
<form id="form1" runat="server">
<table height="100%" cellSpacing="0" cellpadding="0" width="100%" border="0" >
<tr>
<td height="52" align="center">
<asp:Login ID="Login1" runat="server" BackColor="#F7F7DE"
BorderColor="#CCCC99"
BorderStyle="solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="10px" OnAuthenticate="OnAuthenticate"/>
<TitleTextStyle BackColor="#6B696B" Font-Bold="True"
ForeColor="#FFFFFF" />
</asp:Login>
<br/>
<a href="CreateUser.aspx">new user register </a>
</td>
</tr>
</form>
</body>
</html>
少了个/
--------------------编程问答-------------------- public partial class Logon
===============
这里换一个类名,比如 LoginForm
public partial class LoginForm
别忘了aspx也要修改
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="LoginForm" %>
你的类名和ASP.NET提供的控件名冲突了
--------------------编程问答-------------------- Microsoft .NET Framework Version:1.1.4322.2407; ASP.NET Version:1.1.4322.2407
===
貌似用的.NET 1.1,那应该不是我刚才提到的问题,sorry
补充:.NET技术 , C#