LoginProcess
Login Pgae Default.aspx
First of all Import the SQL Client Fucnctions and Features using the following code
using System.Data.SqlClient ;
Add the follwing Code to set the Login Buttons Click Event function,that checks the UserName and password which you entered with the data in the database,if they are matching then the page get navigated into Welcome.aspx
//When the Login Button clicks ,then the following function clls and Execuits the process
protected void LoginBtn_Click(object sender, EventArgs e)
{
string sp = ConfigurationManager.ConnectionStrings["ConnectDB"].ConnectionString ;
string query = "SELECT * FROM Users WHERE id = @id AND pass = @pass " ;
SqlConnection con = new SqlConnection ( sp ) ;
SqlCommand cmd = new SqlCommand ( query , con ) ;
con.Open ( ) ;
cmd.Parameters.Add(new SqlParameter( "@id" , UsrNameTB.Text ) ) ;
cmd.Parameters.Add(new SqlParameter( "@pass" , PasswordTB.Text ) ) ;
SqlDataReader dr = cmd.ExecuitReader ( ) ;
if( dr.Read( ) )
{
string id = dr[ "id" ].ToString( ) ;
Response.Redirect( "Welcome.aspx?name="+id );
}
else
{
Label3.Text = "LoginFailed " ;
}
}
If the login Process is a success then the page redirected io Welcome.aspx,In the Welcome.aspx the following code will set a welcome messege for the user who loged in.
protected void Page_Load(object sender, EventArgs e)
{
WelcomeLbl.Text = " Welcome: " + Request.QueryString[ "name" ].ToString( ) ;
}

No comments:
Post a Comment