Login Page In Asp.net Using 3-Tier Architecture
Introduction : This tutorial explain How to login in asp.net application with use the 3-tier Architecture You can you can use the sql server database and visual studio with following step.
Step :1 Open visual studio and create asp.net web project then create the sql server database with login table. In login table You can let two field name & password
Step :2 Now you can add class DAL.CS this class is known as first tier means it is data access layer
public class DAL
{
public int id { get; set; }
public string name { get; set; }
public string password { get; set; }
public string city { get; set; }
}
Step 3 : Now you can add another Class BAL.CS this class known as Logical layer here we can write the busseness query.
public class BAL
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\program\SESSionDemo\SESSionDemo\App_Data\db1.mdf;Integrated Security=True;User Instance=True");
public DataTable login_data(DAL da)
{
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter("select * from user_master where name='" + da.name + "'and password='" + da.password + "'", con);
sda.Fill(dt);
return dt;
}
Here datatable can be used to return the data from the database SqlAdapter can select the data though the Query .
Step 4 : Now you can Add WebForm and Give name SignIn.aspx then add two TextBox and Submit Button & add Code in CodeBehind file.
namespace SESSionDemo
{
public partial class SignIn : System.Web.UI.Page
{
DAL da = new DAL();
BAL ba = new BAL();
DataTable dt=new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
da.name = TextBox1.Text;
da.password = TextBox2.Text;
dt = ba.login_data(da);
if (dt.Rows.Count > 0)
{
Response.Redirect("home.aspx");
}
else
{
Response.Write("<script>alert('Not Valid User.......')</script>");
}
}
}
}
When you enter user name and password in textbox & if user name and password are correct then it redirect to Home.aspx page if name & password are incorrect it display dialog "Not valid user". run project and check output.
See Other Tutorial :
* AngularJS Crude With ASP.NET MVC
* Convert Rows to columns using 'Pivot' in SQL Server
* Mvc Registration page With user exist using Ajax method
* MVC 4 How to Perform Insert Update Delete Edit Select Operation
* MVC4 Edit,update,Delete,cancel inside gridview using sql database
* MVC 4 Gridview To Display Data Using SQL Server Database With Simple code
* Login page in asp.net Mvc4 Web application
* Mvc4 How to bind Dropdown List using Sql Database
* Gridview find control in asp.net
Sign up here with your email
ConversionConversion EmoticonEmoticon