ASP.NET is a server-side web application development framework allowing developers to build web applications, websites, and web services. It was first introduced by Microsoft in early 2002, and in these 14 years, it has undergone a lot of changes.
Basically, ASP.NET has three programming models:
- ASP.NET Web Forms
- ASP.NET Web Pages
- ASP.NET MVC
Even though the end result of all of the preceding programming models is to produce the dynamic web pages effectively, the methodologies that they follow differ from each other. Let us discuss each one of these programming models to understand their principles.
Historically, when ASP.NET was first introduced, ASP.NET Web Forms was the only programming model available to programmers to develop web applications in ASP.NET.
The ASP.NET Web Forms model abstracted the web so that it can maintain the state even though the web is inherently stateless.
It also supports the event-driven programming model at the server-side. This has helped desktop application developers to have a smooth transition in moving into web application development.
Like PHP and several other web application frameworks, ASP.NET Web Forms is a file-based framework where users access the web page by means of accessing a file at the server. The server will process your request, convert all of your server-side components in that file to HTML, and send it back to the requesting client.
Each web page in ASP.NET Web Forms is represented by two files: .aspx
and .aspx.cs
or .aspx.vb
. The .aspx
file contains your front end components-all of your ASP controls and your HTML elements. The .aspx.cs
(if you are using C# as the code-behind language) or .aspx.vb
(if you are using Visual Basic as the code-behind programming language) contains the code for events which are happening at the web page.
This was the predominant programming model prior to the arrival of ASP.NET MVC, and this programming model is still being used to maintain the production applications that were written using this model.
ASP.NET Web Pages are primarily targeted at small web applications where the data-processing logic is written directly on the web page.
ASP.NET MVC is the implementation of the MVC pattern in ASP.NET. The disadvantages of ASP.NET Web Forms, such as limited control over the generation of HTML are resolved in ASP.NET MVC. As most of the modern applications are controlled by client-side JavaScript libraries/frameworks, such as jQuery, KnockoutJS, and AngularJS, having complete control over the generated HTML is of paramount importance.
Let us talk a bit about the Model-View-Controller pattern and how it benefits the web application development.
Model-View-Controller (MVC) pattern: This is a software architectural pattern which helps in defining the responsibility for each of the components and how they fit together in achieving the overall goal. This pattern is primarily used in building user interfaces, and is applicable in many areas including developing desktop applications and web applications. But I am going to explain the MVC pattern from the context of web development.
Primarily, the MVC pattern has three components:
- Model: This component represents your domain data. Please note that this is not your database. This model component can talk to your database, but the model only represents your domain data. For example, if you are building an e-commerce web application, the model component may contain classes such as Product, Supplier, and Inventory.
- View: This component is responsible for what to present to the user. Usually, this component would contain your HTML and CSS files. This may also include the layout information governing how your web application looks to the end user.
- Controller: As the name implies, the controller is responsible for interacting with different components. It receives the request (through the routing module), talks to the model, and sends the appropriate view to the user.
This separation of responsibilities brings great flexibility to the web application development, allowing each area to be managed separately and independently.