protected void Button1_Click(object sender, EventArgs e)
    {
        string verifyCode = TextBox1.Text;
        string verifyCodeValue = Session["admin_Login"].ToString();        if (string.IsNullOrEmpty(verifyCode) || string.Compare(verifyCode, verifyCodeValue, true) != 0)
        {
            Response.Write("<script>alert('验证码输入不正确!')</script>");
            return;
        }
        else
        {
            string wyxpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(wyx_pass.Text, "MD5");//将输入的密码转换成MD5加密法
            string strConn = ConfigurationManager.ConnectionStrings["SperConnectionString1"].ToString();
            SqlConnection ConnSql = new SqlConnection(strConn);
            ConnSql.Open();
            string strSQL = "SELECT * FROM wyx_user WHERE wyx_name='" + wyx_name.Text + "' AND wyx_pass='" + wyxpassword + "'";
            SqlCommand cmd = new SqlCommand(strSQL, ConnSql);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read()) //如果用户密码正确
            {
                Session["username"] = wyx_name.Text;
                Response.Redirect("admin_index.aspx");//转向后台管理首页   
            }
            else
            {
                Response.Write("<script>alert('嘿嘿,用户或密码不正确!')</script>");//弹出提示信息
            }
            dr.Close();
        }

解决方案 »

  1.   

                HttpCookie cookie = new HttpCookie("admin");
                cookie.Value = "100";
                HttpCookie cookie1 = new HttpCookie("un");
                cookie1.Value = Server.UrlEncode("zhoulei");
                Response.Cookies.Add(cookie);
                Response.Cookies.Add(cookie1);
      

  2.   

    http://msdn.microsoft.com/zh-cn/library/ms178194(VS.80).aspx 
    去MSDN看看,这里有完整的使用方法和例子。
      

  3.   


    这个放在哪里啊?
    还有如果怎么判断cookie?
      

  4.   

    好好看看我给你发的地址,http://msdn.microsoft.com/zh-cn/library/ms178194(VS.80).aspx 
    你要学着自己解决问题,而不是别人喂你。
    msdn上说的很清楚,稍微花点时间看看,你会有好多的收获。
      

  5.   

    if (dr.Read()) //如果用户密码正确
                {
                    string cookieName = "ACOOKIES";
                    HttpCookie Hc = new HttpCookie(cookieName);
                    Hc.Value = wyx_name.Text;
                    Hc.Expires = DateTime.Now.AddDays(1);
                    Response.Cookies.Add(Hc);
                    Response.Redirect("admin_index.aspx");//转向后台管理首页   
                }
      

  6.   

    也可以在客户端通过js脚本写入cookies,总的来说cookies是保存在本地。