http://localhost:49393/WebSite/Default.aspx.cs结合mysql

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        string username = this.Login1.UserName;
        string userpass = this.Login1.Password;
        bool b = this.Login1.RememberMeSet;
        
        MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection("Server=127.0.0.1;Database=mydata;User Id=root;Password=");
        MySql.Data.MySqlClient.MySqlCommand comm = new MySql.Data.MySqlClient.MySqlCommand("select count(*) from t_user where username = ?username and userpass = ?userpass", conn);
        comm.Parameters.AddWithValue("username", username);
        comm.Parameters.AddWithValue("userpass", userpass);
        conn.Open();
        object o = comm.ExecuteScalar();

        int i = Convert.ToInt32(o);
        if (i < 1)
        {
            return;
        }
        Response.Cookies["username"].Value = username;
        Response.Cookies["userpass"].Value = userpass;
        if (b)
        {
            Response.Cookies["username"].Expires = DateTime.Now.AddHours(1);
            Response.Cookies["userpass"].Expires = DateTime.Now.AddHours(1);
        }
        Response.Redirect("~/Index.aspx");
        conn.Close();
    }
}

你可能感兴趣的:(http://localhost:49393/WebSite/Default.aspx.cs结合mysql)