ASP.NET做网站遇到问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 15:06:43
我在做登陆的 代码如下:
public partial class Logon : System.Web.UI.Page
{

protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
}
private bool SiteSpecificAuthenticationMethod(string UserName, string Password)
{
string strUserName, strPWD;
string strSql;
SqlDataReader 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();

明显当myReader.Read()为False时候
SiteSpecificAuthenticationMethod(string UserName, string Password)
没有返回值
修改为:
private bool SiteSpecificAuthenticationMethod(string UserName, string Password)
{
string strUserName, strPWD;
string strSql;
SqlDataReader 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
{