comment je peut s'identifier avec session dans asp.net

HIND BENKOUCH 1 Reputation point
2021-05-10T15:57:15.633+00:00

protected void Button1_Click1(object sender, EventArgs e)
{ //login page et la validation de user et password dans BD:

        string r = "";
        SqlConnection cn = new SqlConnection("Data Source=DESKTOP-F59JVLO;Initial Catalog=GestionCommerciale;Integrated Security=True");
        cn.Open();
        SqlCommand cmd = new SqlCommand("select concat(Nom,' ',Prenom)as utilisateur, Mot_Passe  from Gestionnaire where CONCAT(Nom,' ',Prenom)=@a and Mot_Passe=@b ", cn);
        cmd.Parameters.AddWithValue("@a",TextBox1.Text);
        cmd.Parameters.AddWithValue("@b",TextBox2.Text);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            r = dr[0].ToString();
        }
        dr.Close();
        cn.Close();
        if (TextBox1.Text != null)
        {
            Session["log"] = TextBox1.Text;
            Response.Redirect("MiseAjourClient.aspx?login=" + TextBox1.Text);
        }
        else
        {
            Response.Write("le nom de l'utilisateur ou Mot de passe incorrect!");
        }
    }
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,181 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,291 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,061 Reputation points
    2021-05-11T05:16:46.217+00:00

    Hi @HIND BENKOUCH ,
    According to your description and codes,I'm guessing that your problem is you can't use session when the user login.
    In your codes,I have a problem.You shouldn't check if the textbox is null. You should check if the "r" is null after read the data.

    Best regards
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments