我用visual studio,我做了几个页面了,a.asp,b.asp,
现在我想做一个登录界面,可以输入用户名和密码,然后核对后台数据库A的表account里的两个列user和password,如果对就登录到a.asp,如果不对就显示帐号或密码错误。
这个界面应该怎么做?麻烦给个教程。
问题补充:
我按书上写的添加了LOGIN控件,并写如下代码,但为什么登录总是登录不到呢,是不是数据库的读取和核对那里有什么写错了。
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true)
{
Response.Redirect("Home.aspx");
}
}
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
{
bool boolReturnValue = false;
// Insert code that implements a site-specific custom
// authentication method here.
// This example implementation always returns false.
string strConnection = "server=.;database=UserInfo;uid=sa;pwd=sa;";
SqlConnection Connection = new SqlConnection(strConnection);
String strSQL = "Select * From UserInfo";
SqlCommand command =new SqlCommand(strSQL, Connection);
SqlDataReader Dr;
Connection.Open();
Dr=command.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString()))
{
boolReturnValue = true;
}
}
Dr.Close();
return boolReturnValue;
}