本文介绍了如何在我的代码上添加Cookie。请通过编辑我的代码来帮助我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System..Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace logindemo
{
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connetionString = "Data Source=INFND-DTP-0493;Initial Catalog=Test_DB;User ID=alok;Password=abcd@1234";
SqlConnection conn = new
SqlConnection(connetionString);
conn.Open();
string commText = "Select * from login where User_name='" + TextBox1.Text.Trim() + "' and Password='" + TextBox2.Text.Trim() + "'";
SqlCommand cmd =new
SqlCommand(commText, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (!dr.Read())
{
Response.Write("Invalid User");
}
else
{
conn.Close();
Session["Username"] = TextBox1.Text;
Response.Redirect("WebForm1.aspx");
}
/*else
{
conn.Close();
Response.Redirect("~/welcometo.aspx");
}*/
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = String.Empty;
TextBox2.Text = String.Empty;
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("~/Register.aspx");
}
}
}
推荐答案
这篇关于如何在我的代码上添加Cookie。请通过编辑我的代码来帮助我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!