This article explains how to create and implement a 3-tier architecture for our project in ASP.NET.


What is a Layer?
A layer is a reusable portion of code that performs a specific function.
In the .NET environment, a layer is usually set up as a project that represents this specific function. This specific layer is in charge of working with other layers to perform some specific goal.
Let’s briefly look at the latter situation first.
Data Layer
A DAL contains methods that help the Business Layer to connect the data and perform required actions, whether to return data or to manipulate data (insert, update, delete, and so on).
Business Layer
A BAL contains business logic, validations, or calculations related to the data.
Though a website can talk to the data access layer directly, it usually goes through another layer called the Business Layer. The Business Layer is vital in that it validates the input conditions before calling a method from the data layer. This ensures the data input is correct before proceeding and can often ensure that the outputs are correct as well. This validation of input is called business rules, meaning the rules that the Business Layer uses to make “judgments” about the data.
Presentation Layer
The Presentation Layer contains pages like .aspx or Windows Forms forms where data is presented to the user or input is taken from the user. The ASP.NET website or Windows Forms application (the UI for the project) is called the Presentation Layer. The Presentation Layer is the most important layer simply because it’s the one that everyone sees and uses. Even with a well-structured business and data layer, if the Presentation Layer is designed poorly, this gives the users a poor view of the system.
Advantages of a 3-Tier Architecture
The main characteristic of a Host Architecture is that the application and databases reside on the same host computer, and the user interacts with the host using an unfriendly dumb terminal. This architecture does not support distributed computing (the host applications are unable to connect to a database of a strategically allied partner). Some managers find that developing a host application takes too long and is expensive. These disadvantages consequently led to a Client-Server architecture.
A Client-Server architecture is a 2-tier architecture because the client does not distinguish between a Presentation Layer and a Business Layer. The increasing demands on GUI controls caused difficulty in managing the mixture of source code from a GUI and the Business Logic (Spaghetti Code). Further, the Client Server Architecture does not support enough Change Management. Let us suppose that the government increases the Entertainment tax rate from 4% to 8 %; then, in the Client-Server case, we need to send an update to each client, and they must update synchronously at a specific time; otherwise, we may store invalid or incorrect information.
The Client-Server Architecture is also a burden to network traffic and resources. Let us assume that about five hundred clients are working on a data server. Then, we will have five hundred ODBC connections and several Ruffian record sets that must be transported from the server to the clients (because the Business Layer remains in the client side). The fact that Client-Server does not have any caching facilities like in ASP.NET causes additional traffic in the network. Normally, a server has better hardware than the client, therefore it is able to compute algorithms faster than a client, so this fact is also an additional argument in favor of the 3-Tier Architecture. This categorization of the application makes the function more reusable easily, and it becomes too easy to find the functions that have been written previously. If a programmer wants to make further updates in the application, then he can easily understand the previously written code and can update it easily.
Let's start creating a 3-Tier Architecture Application.
1. Create a new project using "File" -> "New" -> "Project...".

2. In Visual C#, select "Web".
(Select "ASP.NET Web application" and name it’s as ThreeTierApp)

3. How to add the class library to the solution:

After clicking on a new project, you will see the following screen.
- Select "Class Library" from this and name it "BussinessObject".

- Provide the name of the Class library as "BussinessObject".

- Add another Class Library to our project.
(In the same way as you added a BussinessObject.)
- Name the Class library "Bussinesslogic".
- After adding, you will see as in this view.

- Add the last Class Library to our project called "Data Access Layer".
- In the same way, as you added BussinessObject.
- Name the Class Library "DataAccess".

After adding, your solution would look like this:

Now we are done. Add all layers to our project.
You can see the three tiers in the image given below.

Basically, a 3-Tier architecture contains the following 3 layers:
- Application Layer or Presentation Layer (our web form and UI Part)
- Business Logic Layer (Bussinesslogic)
- Data Access Layer (DataAccess)
Here I will explain each layer with a simple example that is a User Registration Form.
Presentation Layer
Here, I have designed a user interface for the Presentation Layer.







Cymon MaxwellPosted Aug 3, 2023, 9:33 PM
I tried running the application but it had build errors. These are specifically to with sqlconnection. Kindly assist
pankaj kalePosted Jun 30, 2021, 1:45 PM
I have to do all step you have been mention in (last step) I am could not add reference of all 3 layers. so how to fix this please help me.
MANUEL PEREZPosted Feb 24, 2021, 3:42 AM
In the case of reading a text file, the information must be loaded from the Data Layer?
Nihal LatifPosted Feb 9, 2020, 3:24 AM
Hi Sainesh, first of all very good article, I have one question, how can we deploy logic, object and data on three different machines and the actual database on a 4th machine for scalibility, faster performance etc. Thanks.
Premdas VmPosted Nov 2, 2019, 6:40 AM
Hai, Can i use web api and json, on a three tier web application? every tutorial i look for ends up on MVC based ones.
Pritish ShrikhandePosted Nov 16, 2018, 3:21 AM
UserBL is not showing in aspx.cs file even after adding "using BusinessLogic" on top.
Vikash VishwakarmaPosted Feb 6, 2018, 5:01 AM
I have followed all your guideline but ConfigurationManager is not working in UserDA.cs file and "using BussinessObject" is not accessible in UserBL.cs file. How to over come this problems ?
Jume MiPosted Nov 28, 2017, 3:34 PM
Hello. I have one proyect using 3Tier architecture. I would like to know how to publish this in IIS. For a normal ASP web forms I used to copy a folder that included the .aspx files, content, bin and some other files. But wirh 3 tier I am not sure which folder should I copy
Sudhakar RaoPosted Sep 26, 2017, 3:02 PM
Very nice article, thank you bro. Took me less than 10 mins to upgrade to VS 2013, setup and run the project.
Ari FPosted Aug 28, 2017, 12:50 PM
Thank you Saineshwar for what is a genuinely a terrific article. It is extremely valuable in that it presents a simple and concise example that is clean and scalable. As simple as the example is, it presents a much LARGER lesson, and it is serving me extremely well in my career for a solution I am currently developing. It is kinda funny reading some of these comments that miss the entire value of this article. “The definition of genius is taking the complex and making it simple.”" - Albert Einstein
deepu tiwariPosted Aug 21, 2017, 8:21 AM
This is Wrong.. People Don't consider it
Ankita ShilpaPosted Jun 22, 2017, 4:00 AM
BtnSave_Click - what is the code of this click event?
anitha TPosted Jun 5, 2017, 5:19 AM
Its very nice article but if we want to store unique email id's then
Jason CanneyPosted Mar 27, 2017, 4:26 PM
Where does your asp form link to your userBL method?
Anil Kumar MurmuPosted Nov 23, 2016, 9:40 AM
Hey, We call an application 3 layer if all the 3 layers are deployed in single server. However, if they are in different physical server then it would be considered as 3 tier. In 3-tier application, your application layer , dataAccess layer and Business layer would in in 3 different servers.
Jai Prakash SaraswatPosted Nov 21, 2016, 8:04 AM
Thanks sir. Working Fine.. But.. Can u explain... this is 3 tire or 3 layer... If three layer.. than pl.. tell me what is different b/w 3 layer and 3 tire architecture...
Vithal WadjePosted Nov 20, 2016, 3:22 AM
As per my best knowledge this not a 3 tier architecture or may be I am not getting . its typical example of layer architecture so title may be layer architecture instead of tier, Mahesh Chand sir Vidya Vrat Agarwal sir can you explain about this in your next articles .
Ankur VermaPosted Sep 30, 2016, 7:23 AM
Good
Rahul JoshiPosted Sep 8, 2016, 4:56 AM
Amazing Article. Perfect learning solution for the newer student or professional.
VandanaPosted Sep 3, 2016, 6:42 AM
Perfect Article each things defined clearly but one must download the file after doing these things mention above. thank you! Sir
SubashPosted Aug 30, 2016, 12:29 PM
Thanks
SubashPosted Aug 30, 2016, 12:29 PM
How canwe create n tier in windows application
kalu singh raoPosted Jul 7, 2016, 1:39 AM
Nice...
Avinash KesipeddiPosted Jul 3, 2016, 2:41 PM
Thank You Sir, I have tried the above example Many times but every time it is not showing any error but the button "Save" is not performing any Action????
Vikash KumarPosted Jun 8, 2016, 2:00 AM
Yes yes. I have used that
Vikash KumarPosted Jun 8, 2016, 1:19 AM
Hey I got the above error. I am very new to it. Am I missing anything?
Vikash KumarPosted Jun 7, 2016, 12:49 PM
<asp:Button ID="BtnSave" runat="server" Width="100px" Text="Save" OnClick="BtnSave_Click" /> This is the error I get. CS1061: 'ASP.userregistration_aspx' does not contain a definition for 'BtnSave_Click' and no extension method 'BtnSave_Click' accepting a first argument of type 'ASP.userregistration_aspx' could be found (are you missing a using directive or an assembly reference?)
Vikash KumarPosted Jun 7, 2016, 3:29 AM
New rebuild all layers. Last step Right-click on the project and select "Add references" Click the "Add Reference" tab Select "Project" Inside that you will see all Layer Name. Select all add thn click "Ok" Now build the project. If I try to add a reference to Business Object and data access and again, it doesn't allow. I didn't understand this step. Is there something I am missing. And it doesn't recognise BusinessObject Namespace in UserDA.cs thoughI have added BusinessObject refereance.
Thiruppathi RPosted Jun 3, 2016, 2:48 AM
Indepth article for 3tier .thanks..
MASOOD AHMADPosted Mar 6, 2016, 7:02 AM
Nice article but i have one question, What is the different between layering(project) and tier.
Anil Kumar MurmuPosted Feb 16, 2016, 1:04 AM
nice article
ranjan sawPosted Jan 15, 2016, 4:43 AM
it realy helpfull for begener....................
Harsh KumarPosted Jan 9, 2016, 3:34 AM
how to display data in a gridview using ur code structure.
Dipak TipalePosted Jan 6, 2016, 2:23 AM
useful artical
Harsh KumarPosted Jan 4, 2016, 11:16 AM
nice artical.. very usefull
Shiv YadavPosted Nov 29, 2015, 1:25 PM
http://asp3tier.blogspot.in/p/aspnet-3-tier-architecture.html
Ajay KadamPosted Nov 28, 2015, 7:40 AM
Nice artical sir..Thanks
Sujeet SumanPosted Oct 24, 2015, 11:08 AM
Nice article..............
Ajeet MishraPosted Sep 15, 2015, 2:41 AM
Nice
mayur patelPosted Sep 7, 2015, 11:57 AM
How to implement AJAX usinf WebMethod-Entity in this architecture ?
George TourtsinakisPosted Aug 12, 2015, 6:53 AM
I m new to .net programming and accidentally dropped in an article about 3 tiers when creating an asp.net.I understood clearly with your explanation and great names you give in your project.Thank you for sharing.
Raju KingPosted Aug 5, 2015, 11:53 PM
WHERE IS THE BUTTON CLICK CODE
nitin malikPosted Jul 23, 2015, 7:56 AM
and also getting error in Register public int SaveRegisterBAL(Register? objRegisterBAL)
nitin malikPosted Jul 23, 2015, 7:51 AM
Can u please teel me i need to be write page behind code of my aspx file in that 3 tyre arch..
Upendra Pratap ShahiPosted Jun 8, 2015, 7:32 AM
nice...
Shubham JainPosted May 4, 2015, 5:33 AM
sprocUserinfoInsertUpdateSingleItem and will u please elobrate the sp as well
Shubham JainPosted May 4, 2015, 5:28 AM
Very Good Solution can we implement the same with angular.js
shyam sunderPosted May 1, 2015, 3:01 PM
good aritcle
Saineshwar BageriPosted Apr 22, 2015, 2:31 AM
Its your .aspx page
jaya prakashPosted Apr 22, 2015, 1:49 AM
where to write presentation layer code(html)
deepthi sandhyaPosted Apr 21, 2015, 1:05 AM
Issue Solved Thank you
deepthi sandhyaPosted Apr 20, 2015, 9:23 AM
Showing error not all code paths return a value how to do solve it..
Saineshwar BageriPosted Apr 20, 2015, 9:10 AM
then whats problem Deepthi
deepthi sandhyaPosted Apr 20, 2015, 6:50 AM
Presentation layer public void BindLeaveList() { DataTable dt = Logic.GetLeavelist(Session["Username"].ToString(), Session["UserAcess"].ToString()); drpdwnLeavetype.DataSource = dt; drpdwnLeavetype.DataValueField = "id"; drpdwnLeavetype.DataTextField = "Leavename"; drpdwnLeavetype.DataBind(); drpdwnLeavetype.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Select", "0")); }
deepthi sandhyaPosted Apr 20, 2015, 6:48 AM
Bussiness logic public DataTable GetProjectNamesList(string strUserName, string strUserAccess) { try { DataTable dsProj = new DataTable(); dsProj = da.Get_ProjectNamesList(strUserName, strUserAccess, ); } catch (Exception ex) { throw ex; }
deepthi sandhyaPosted Apr 20, 2015, 6:47 AM
Data Access Layer public DataTable Get_ProjectNamesList(string strUserName, string strUserAccess,DBManager db) { try { string strProj = string.Empty; if (strUserAccess == "2") strProj = "Select Id,projectname from tb_Projects where Isdelete = 0 and Isarkive=0 and clientname='" + strUserName + "' order by 'projectname' "; else strProj = "Select Id,projectname from tb_Project where Isdelete = 0 and Isarkive=0 order by 'projectname'"; DataSet dsProj = db.ExecuteDataSet(CommandType.Text, strProj); return dsProj.Tables[0]; } catch (Exception ex) { throw ex; } }
deepthi sandhyaPosted Apr 20, 2015, 6:46 AM
I did everything can below is my code ..let me know
deepthi sandhyaPosted Apr 20, 2015, 6:21 AM
Hi how to bind data into dropdown in 3 tier archieture. Using select statement I am unable to get data..Can you please let me know
Mitali PattanayakPosted Apr 17, 2015, 6:18 AM
Well explained as required. Excellent job done !! Thank you !!
Dheeraj PandeyPosted Apr 12, 2015, 9:28 AM
This Article is very simple and easy for me, Today my doubt have cleared about 3 tire architecture ...... thanks sir
Priya BhoslePosted Mar 24, 2015, 2:44 PM
very helpful to clear concept and actual work.....Thanks...
Saineshwar BageriPosted Mar 3, 2015, 1:59 AM
follow steps as i have written you will get
Muhammad RizwanuddinPosted Mar 3, 2015, 1:17 AM
yes sir pls help
Saineshwar BageriPosted Feb 27, 2015, 5:32 AM
Muhammad Rizwanuddin sir are u fresher in this technology
Muhammad RizwanuddinPosted Feb 27, 2015, 5:29 AM
sir i don't understand
Abrar KaziPosted Feb 25, 2015, 2:55 AM
What is the code at button click
Pramod NairPosted Feb 19, 2015, 12:34 AM
Very Nicely explained, excellent article
Saineshwar BageriPosted Jan 17, 2015, 11:22 PM
thanks Md. Raskinur Rashid sir
Md. Raskinur RashidPosted Jan 17, 2015, 11:34 AM
very good presentation. i will share it everyone those who want to learn N-tier architecture
Santosh bindPosted Dec 19, 2014, 1:05 AM
hi it is very simple and nice article everyone can understand easily this is achieve by your better effort and hardworking thanks a lot of
venkatesan kPosted Nov 18, 2014, 1:34 AM
very helpfull for me
Ramoo PrajapatiPosted Nov 18, 2014, 1:05 AM
Very easy article.! Thanks You.!
Saineshwar BageriPosted Oct 10, 2014, 4:59 AM
hirachand here is link :- http://www.visualstudio.com/en-us/downloads#d-professional
hirachand mudhalePosted Oct 10, 2014, 3:26 AM
please anyone give me a visual studio 2013 setup link
Amit SinghPosted Oct 9, 2014, 5:53 AM
how to write 3 tier insert code in gridview please help me
shimith vkPosted Oct 6, 2014, 7:27 AM
its very good article .. thank u
Marc McElrathPosted Sep 18, 2014, 1:02 PM
Thank you for your response. I am very well aware of the differences between a 3-tier architecture and the MVC design methodology. It is good you pointed this out since some people think that MVC is an architecture. My question was: "Can you use an implementation like this to to implement a 3-tier architecture using MVC?" for instance maybe the Presentation layer is the VC part of MVC and then there is some way to implement the Business Logic and Database Layers by re-configuring the existing Controller and Model so that the Controller becomes thin and the BL becomes fat. and then speaks with the Model layer of the 3-tier architecture. I ask this question since I have seen a lot of talk about it but not yet have I found an example of it's implementation. I have not yet checked the link you posted but I wanted to clarify that there was no confusion in the differences between MVC and 3-tier.
Saineshwar BageriPosted Sep 18, 2014, 12:26 AM
you can add DAL to Project and Work with it http://tutoriz.com/Thread-CREATE-3-TIER-ARCHITECTURE-IN-ASP-NET-MVC-DAL-BLL-Part-1-3
Saineshwar BageriPosted Sep 18, 2014, 12:25 AM
MVC and 3-tier architecture are different things all together. If they were the same, then anybody with a 3 tier architecture would by definition have implemented MVC. Since that would be a false statement, we can safely say that they are not the same thing. MVC has specific architectural patterns as to how the tiers interact that differ from a straight 3 tier architecture.
Marc McElrathPosted Sep 17, 2014, 1:22 PM
Can this implementation be applied to a MVC 5 project? I would like to convert my existing VS 2013 MVC 5 project to a 3-tier architecture, but this example is in VS 2012 for a regular web application.
Saineshwar BageriPosted Sep 13, 2014, 9:06 AM
download code you will get Purvesh Sangani sir
Purvesh SanganiPosted Sep 13, 2014, 4:50 AM
hello Mr. Saineshwar please can you show button code.
Prashant PandePosted Sep 13, 2014, 3:15 AM
Nice Article
ankush agnihotriPosted Sep 8, 2014, 1:34 PM
hello sir,
Shreya SoniPosted Aug 25, 2014, 12:51 AM
I am looking for code to inserting data in to multiple table of database from same insert method in data access class using hash table.. Can u plz help me.?
Shreya SoniPosted Aug 22, 2014, 12:13 AM
Its really very useful. Thank u..
MkPosted Jul 11, 2014, 3:32 AM
thanks so much.This gives a good start for beginners...:) cool
Saineshwar BageriPosted Jul 10, 2014, 8:20 AM
there is code and stored procedure for it just download sample application which i have provided mk sir
MkPosted Jul 10, 2014, 8:11 AM
There is no code for stored procedure and Save button...
Harshal ThakrePosted Jun 10, 2014, 9:23 AM
thanks
Markandeshwar JhaPosted Jun 4, 2014, 8:05 AM
Nice Article and good work.
kalai vananPosted Jun 4, 2014, 2:31 AM
when i inter connect each layer i getting this error A refrence to Buusinesslogic could not be added , Adding this project as a reference would cause a circular dependency
Khan Abrar AhmedPosted May 28, 2014, 10:10 AM
Good Project sir,
Saineshwar BageriPosted May 2, 2014, 1:18 AM
One datatype issue in Store PROCEDURE [sprocUserinfoInsertUpdateSingleItem] ,@EmailID nvarchar=NULL make it @EmailID nvarchar (50)
DERRICK WASHINGTONPosted Apr 25, 2014, 11:25 AM
Good project, but missed explaing about the code behind for the UI (Userregistration.aspx page)
Saineshwar BageriPosted Mar 25, 2014, 4:04 AM
if you download sample in that i have done it please check.
Anshul RPosted Mar 25, 2014, 3:45 AM
Yes, i got that point. But to make the code work, dont we need to incorporate the above mentioned points 1 & 2 in the code sample? Thanx in advance
Saineshwar BageriPosted Mar 24, 2014, 11:55 PM
1)We need to pass all values of controls to Business object 2) And then send Business object to Business logic layer after this it will be connected to DataAccess class. if you got then Please Reply me sir.
Anshul RPosted Mar 24, 2014, 3:41 PM
1) I think we need to add a reference of Business object in the Business logic, 2)Configuration Manager(for database connection has to referenced in each of the individual projects ,otherwise it's not accessible through Intellisense), 3) We need to create objects of Business object and Business logic in the Presentation layer(Default.aspx) so as to pass the values from the controls to the properties and then to the Business Logic.
Sapna KansayPosted Mar 10, 2014, 12:03 PM
Thank You really made my job easy :)
manav sharmaPosted Jan 21, 2014, 4:56 PM
Good Work. Thanks for such a good article.
Saineshwar BageriPosted Jan 7, 2014, 11:49 PM
sorry i had not dispose and closed things please do it to save memory leaks 1) ObjBO.Dispose(); 2) con.close();
Saineshwar BageriPosted Jan 6, 2014, 11:51 AM
hey friends are there for u http://dotnet-sai.blogspot.in/
Sujit JhaPosted Jan 6, 2014, 6:11 AM
Very useful Articles...Thanks Saineshwar Sir
Saineshwar BageriPosted Jan 3, 2014, 1:01 AM
Raseeth A now sql script is avaiable
Saineshwar BageriPosted Jan 2, 2014, 11:22 PM
Raseeth A sorry to tell u i have submit my script with code but they have not posted i will give u on 4/1/2014
Raseeth APosted Jan 2, 2014, 9:43 AM
where is the Store Procedure for Insert (sprocUserinfoInsertUpdateSingleItem)
Saineshwar BageriPosted Dec 30, 2013, 11:19 PM
Thanks Sam Hobbs sir
Sam HobbsPosted Dec 30, 2013, 6:43 PM
Thank you for providing a simple explanation of a complex and useful topic. I think this will help many people. Note however that it helps to be careful about the historical perspectives when they are provided. I want to say that in truth, the reason for the old-fashion Host Architecture was that at the time of its use (with Dumb Terminals) smart terminals were very expensive. Yes dumb terminals were unfriendly but smart terminals were very unfriendly to the managers that had to justify the huge cost. Note also that it is absolutely not true that a Host Architecture was not capable of distributed databases. Distributed databases existed long before Microsoft and the internet existed.
Mahesh ChandPosted Dec 30, 2013, 9:42 AM
You're welcome Saineshwar.
Saineshwar BageriPosted Dec 30, 2013, 1:27 AM
thanks sir
Mahesh ChandPosted Dec 30, 2013, 1:16 AM
Nicely explained Saineshwar. Love the second diagram. A tier usually means a separate hardware layer. So 3-tier means your UI (website) can be hosted on a Web Server, Business layer can be hosted on a different server that is doing lot of business processing and your database layer (SQL Server for example) is hosted on a different server.