This tutorial explains how to implement a Login page using 3-Tier Architecture in ASP.Net. I have described it in details. You will also get many new and known concepts to learn in this article whether on the SQL Server Query or C# code side.
In previous tutorial we have learn How to create a login page using asp.net mvc
Step :1 Open visual studio and create asp.net web project then create the sql server database with login table.in login table add field name and 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 business query for for check login name and password is correct or not
public class BAL
{
SqlConnection con = new SqlConnection(@”Data Source=.\SQ;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;
}
Step 4 : Now you can Add WebForm and Give name SignIn.aspx then add two TextBox and Submit Button & add Code in CodeBehind file.
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 alert massage “Not Valid User…….“.
SEE MORE
- Auto Refresh Partial View in ASP.NET MVC
- What is ASP.NET Core
- Difference between TempData keep() And Peek() in Asp.Net MVC
- Difference between viewbag,viewdata and tempdata in asp.net mvc
- ASP.NET MVC With AngularJS
- Retrieving Data Using Form Collection and Inserting Into ASP.Net MVC
- MVC CRUD Operations Using Entity Framework
- Search Functionality in ASP.NET MVC
- How to create a User Registration page using asp.net mvc
- Store Multiple Checkbox state from cookie using Jquery
- Cascading Dropdownlist using Ajax in Asp.Net Mvc with city state country
- Insert, Update, Delete In GridView Using ASP.Net C#
- Binding Dropdownlist With Database In Asp.Net MVC
- Search and Filter data in Gridview using Asp.net MVC
- Select Insert, Update And Delete With ASP.NET MVC
- Display Data in GridView Using Asp.net MVC
- Validation in ASP.NET MVC Razor view
- CRUD Operation Using 3-Tier Architecture In ASP.NET
- How to get Connection String from Web.Config in Asp.Net C#
- Login page using 3-Tier Architecture in ASP.Net
- Asp.Net Image Upload in 3-Tier Architecture and store in sql database
13 Comments