ログインが成功したら、私は自分のログインページからホームページにどのようにリダイレクトできますか? 私はこの中にユーザー名とパスワードを格納しているデータベースを1つ持っています。 ログイン時に、ユーザー名とパスワードをSQLクエリで確認します。 私のコードは以下の通りです。ページのリダイレクト
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
Label3.Visible = true;
Label3.Text = "* Required Field";
}
else if (TextBox2.Text == "")
{
Label4.Visible = true;
Label4.Text = "* Required Field";
}
else
{
Label3.Visible = false;
Label4.Visible = false;
userid = TextBox1.Text;
pass = TextBox2.Text;
SqlConnection conn = new SqlConnection("SERVER= server3\\OFFICESERVERS; Initial catalog = Web; Integrated Security = SSPI");
SqlCommand mycmd = new SqlCommand();
mycmd.Connection = conn;
mycmd.CommandText = "SELECT FirstName, LastName, MiddleName, Email, Age FROM web WHERE IsActive=1 AND LoginName='" + userid + "' " + "AND Password='" + pass + "'";
try
{
conn.Open();
mycmd.ExecuteScalar();
SqlDataAdapter da = new SqlDataAdapter(mycmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.Visible=true;
GridView1.DataSource = dt;
GridView1.DataBind();
TextBox1.Text = "";
TextBox2.Text="";
}
finally
{
conn.Close();
conn.Dispose();
}
}
}
私の要件は、ログインが成功した場合、ログインページからホームページにリダイレクトすることです。 どうすればいいですか?
あなたはパンチに私を打つ。いい答え。 – BinaryMisfit