我是新手,下面是我写的一断登录程序的全部代码,试的时候COOKIE总是有问题,感觉整个程序写的也不是特别的顺畅,请哪位高手能帮我修改一下呀,,现再最主要问题是用数据库中已经有的正确用户名,再填一个错误的密码,COOKIE信息还是能显示出来的,但实际是没有登录成功的。namespace RSY
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// top 的摘要说明。
/// </summary>
public class top1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox txtPWD;
protected System.Web.UI.WebControls.TextBox txtUserName;
private SqlConnection Conn;
protected System.Web.UI.WebControls.ImageButton ImButlog;
protected System.Web.UI.WebControls.ImageButton Imagelogin;
protected System.Web.UI.HtmlControls.HtmlTableCell TD1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Panel Panel2;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.HtmlControls.HtmlImage IMG1;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
private RiShengYuanModel.ConnectionSQL ConnSql=new RiShengYuanModel.ConnectionSQL();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//--添加COOKIE信息
Label3.Visible=false;
if (Request.Cookies["Account"] == null)
{
CPublic GetAccount = new CPublic();
DataTable objDT = new DataTable();
string strSQL = "SELECT  *  FROM register where Account = '" + txtUserName.Text.Trim() + "'" ;
objDT = GetAccount.GetDTRecord(strSQL,GetAccount.getConnection());
if (objDT.Rows.Count >0)
{

HttpCookie myCookie = new HttpCookie("Account");
myCookie.Expires = DateTime.Now.AddDays(2); myCookie.Values.Add("Account",objDT.Rows[0]["Account"].ToString().Trim());  Response.AppendCookie(myCookie);
}
} if(Request.Cookies["Account"]!=null)
{
//-取出COOKIE的信息
Label1.Visible=false;
txtUserName.Visible=false;
Label2.Visible=false;
txtPWD.Visible=false;
Imagelogin.Visible=false;
ImButlog.Visible=false;
Label6.Visible=false;
Label3.Visible=true;
HttpCookie myCookie = Request.Cookies["Account"];
Label3.Text= myCookie.Values["Account"].ToString() + " 您好!已登录成功" +"   时间:" + DateTime.Now;
}
if(!Page.IsPostBack)
{
selectIfUse();
}

}//选出服务到期的ID
private void selectIfUse()
{
try
{
string ID=string.Empty;
string sql="select id from BuyServiceInformation where DATEDIFF(day,ServiceTerm,getdate())>=0";
Conn=ConnSql.getConnection();
Conn.Open(); SqlCommand Comm=new SqlCommand(sql,Conn);
SqlDataReader dr=Comm.ExecuteReader();
while(dr.Read())
{
ID=dr["ID"].ToString().Trim();
updateIfUse(ID);
}
dr.Close();
} catch(Exception e)
{

Response.Write(e.Message);
}
finally
{
Conn.Close();
}
}
//更新BuyServiceInformation 表IfUse字段
private void updateIfUse(string ID)
{
try
{
string sql="update BuyServiceInformation set ifuse=@Ifuse where id=@ID";
Conn=ConnSql.getConnection();
Conn.Open(); SqlCommand Comm=new SqlCommand(sql,Conn);
Comm.Parameters.Add("@ID",ID);
Comm.Parameters.Add("@Ifuse","1");
Comm.ExecuteNonQuery();
} catch(Exception e)
{
Response.Write(e.Message);
} finally
{
Conn.Close();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Imagelogin.Click += new System.Web.UI.ImageClickEventHandler(this.Imagelogin_Click);
this.ImButlog.Click += new System.Web.UI.ImageClickEventHandler(this.ImButlog_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private void Imagelogin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
try
{
string sql="select count(*) from register where account=@account and mypassword=@mypassword";
Conn=ConnSql.getConnection();
Conn.Open();
SqlCommand Comm=new SqlCommand(sql,Conn);
Comm.Parameters.Add("@account",this.txtUserName.Text.Trim());
Comm.Parameters.Add("@mypassword",this.txtPWD.Text.Trim()); if(Convert.ToInt32(Comm.ExecuteScalar().ToString())>0) //登陆
{
iflock();
} else
{
Response.Write("<script language=javascript>alert('该用户名或密码不存在');</script>");
}
} catch(Exception oException)
{
Response.Write(oException.Message);
} finally
{
Conn.Close();
}
   
} private void ImButlog_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("denglu/term.aspx");
}
private void iflock() //判断帐号是否已锁定
{
try
{
string Sql = "select iflock from state where account = @account";
Conn = ConnSql.getConnection();
Conn.Open();
SqlCommand Comm = new SqlCommand(Sql,Conn);
Comm.Parameters.Add("@account",this.txtUserName.Text);
SqlDataReader dr = Comm.ExecuteReader(); if(dr.Read())
{
if(dr["iflock"].ToString().Trim()=="否")
}
} catch(Exception e)
{
Response.Write(e.Message);
}
finally
{
Conn.Close();
}
}
//判断帐号是否已挂失
private void ifloss()
{
try
{
string Sql = "select ifloss from state where account = @account";
Conn = ConnSql.getConnection();
Conn.Open();
SqlCommand Comm = new SqlCommand(Sql,Conn);
Comm.Parameters.Add("@account",this.txtUserName.Text);
SqlDataReader dr = Comm.ExecuteReader(); if(dr.Read())
{
if(dr["ifloss"].ToString().Trim()=="否")
{
Session["account"]=this.txtUserName.Text;
Session["PWD"]=this.txtPWD.Text;
// Response.Buffer=true;
// Response.Redirect("../客服中心/转帐/TransferList.aspx");//将要登陆的页面(待定)
//Response.Write("<script language=javascript>alert('登陆成功.');</script>");

                        BuyServiceFellIn();
}
}
} catch(Exception e)
{
Response.Write(e.Message);
}
finally
{
Conn.Close();
}
} private void BuyServiceFellIn()
{
try
{
//DateTime ToDayTime=DateTime.Now;
string sql="select count(*) from BuyServiceInformation where account=@account and ifoverdue=@ifoverdue and"+
" DATEDIFF(day,ServiceTerm,getdate())>=0";
Conn=ConnSql.getConnection();
Conn.Open(); SqlCommand Comm=new SqlCommand(sql,Conn);
Comm.Parameters.Add("@account",this.txtUserName.Text.Trim());
Comm.Parameters.Add("@ifoverdue","否"); if(Convert.ToInt32(Comm.ExecuteScalar().ToString())>0)
{
Response.Redirect("GuoQiFuWu.aspx?account="+this.txtUserName.Text.Trim());
}
} catch(Exception e)
{
Response.Write(e.Message);
} finally
{
Conn.Close();
}
}
}
}