Introduction to ASP.NET MVC - Evolution of ASP.NET MVC

ASP.NET MVC is a framework for developing dynamic Web applications using the .NET Framework. Prior to ASP.NET MVC, dynamic Web applications based on the .NET Framework were developed using ASP. NET Web pages and ASP.NET Web Forms. The following topics discuss about these technologies before explaining how ASP.NET MVC helps in creating more robust and scalable Web applications.

1. ASP.NET Applications 

ASP.NET is a server-side technology that enables you to create dynamic Web applications using advanced
features, such as simplicity, security, and scalability, which are based on the .NET Framework.
ASP.NET applications are comprises the .aspx Web pages that combine both client-side and server-side
scripts to build dynamic Web sites.
Once you create an ASP.NET application, you need to deploy the application on a Web server such as
Internet Information Services (IIS) server, which is the Web server for the Windows platform. The requestresponse flows for an ASP.NET Web page comprises the following steps:
1. Browser sends a request for an ASP.NET Web page.
2. When the request arrives, the IIS server intercepts the request, loads the requested file, and forwards
it to the ASP.NET Runtime for processing.
3. The ASP.NET Runtime that contains the ASP.NET script engine processes the requested ASP.NET page
and generates the response.
4. The IIS server sends back the response to the Web server that requested the page.

2. ASP.NET Web Forms 

The  traditional  ASP.NET  Web  applications  gradually  evolved  to  ASP.NET  Web  Forms  to  simplify development of dynamic Web applications. ASP.NET Web Forms introduced several User Interface (UI) controls that you can drag and drop to design your UI. Some examples of such UI controls are labels, text boxes, radio buttons, and check boxes. Once you drag and drop a UI control in your UI, you can easily set the properties, methods, and events for the control or the form. This enables you to specify how the form and its control should respond at runtime. Similar to traditional ASP.NET Web pages, Web Forms are written by using a combination of HTML, server controls, server code, and users request them through their browsers. It separates the HTML code from the application logic. To write server code for developing the logic for the page, you can use a .NET language, such as Visual Basic or C#. Using Web Forms does not require you to have a hardcore developer background. You just need to be familiar with the user interface controls and event handling. Moreover, Web Forms allow a developer to use CSS, generate semantically correct markup, and handle the development environment created for HTML elements easily. This is because the developers just need to drag and drop the server controls and set their properties for designing the page. The markup of these controls is generated automatically.

3. ASP.NET MVC

ASP.NET MVC is based on the MVC design pattern that allows you to develop software solutions. For this, the MVC pattern provides a reusable solution to resolve common problems that occurs while developing a Web application.
You can use the MVC pattern to develop Web application with loosely coupled components. It is very difficult to manage Web applications that contain tightly coupled components. This is because, updating one component also requires updating the other components. To overcome such problems, you can use the MVC design pattern that enables separating data access, business, and presentation logic from each other.

While using the MVC design pattern, a Web application can be divided in the following three types:
  • Model:  Represents  information  about  a  domain  that  can  be  the  application  data  of  a  Web application. In ASP.NET MVC applications, the model class represents this model.
  • View: Represents the presentation logic to provide the data of the model. There can be multiple views  for  the  same  model.  In  ASP.NET  MVC  application,  the  files  within  the View folder  of  the application directory represent the view.
  • Controller:  Represents  the  logic  responsible  for  coordinating  between  the  view  and  model classes. The controller classes in an ASP.NET MVC application handles events thrown by the view and calls the corresponding model to be processed.
 Figure 1.3 shows the communications between the model, view, and controller components.
 
 Figure 1.3: Communication between the Components of the MVC Pattern

As ASP.NET MVC is based on the MVC design pattern, it helps in developing applications in a loosely coupled manner and provides the following benefits:
  • Separation of concerns: Enables you to ensure that various application concerns into different and  independent  software  components.  Thus,  it  allows  you  to  work  on  a  single  component independently.
  • Simplified testing and maintenance: Enables you to test each component independently. This helps  you  in  ensuring  that  it  is  working  as  per  the  requirement  of  the  application  and  then,simplifies the process of testing, maintenance, and troubleshooting procedures
  • Extensibility: Enables the model to include a set of independent components that you can easily modify  or  replace  based  on  the  application  requirement.  Modifying  or  replacing  these components does not affect the functionality of the application.

4. History of MVC 

Following are the versions that depict the history of MVC:

ASP.NET MVC 1

This  is  the  first  version  of  ASP.NET  MVC.  ASP.NET  MVC  1  was  released  on  March  13,  2009  and targets  .Net  Framework  3.5.  Visual  Studio  2008  and  Visual  Studio  2008  SP1  provide  support  to develop ASP.NET MVC 1 applications.

ASP.NET MVC 2

This version of ASP.NET MVC was released on March 10, 2010 and targets .NET Framework 3.5 and
4.0. Visual Studio 2008 and 2010 provide support to develop ASP.NET MVC 2 applications. ASP.NET
MVC 2 introduced the following key features:
  • Strongly typed HTML helpers means
  • Data Annotations Attribute
  • Client-side validation
  • Automatic scaffolding
  • Segregating an application into modules
  • Asynchronous controllers

ASP.NET MVC 3

This version of ASP.NET MVC was released on January 13, 2011 and targets .NET Framework 4.0. Visual Studio 2010 provides support to develop ASP.NET MVC 3 applications.
ASP.NET MVC 3 introduced the following key features:
  • The Razor view engine
  • Improved support for Data Annotations
  • Dependency resolver
  • Entity Framework Code First support
  • ViewBag to pass data from controller to view
  • Action filters that can be applied globally
  • Unobtrusive JavaScript
  • jQuery validation 

ASP.NET MVC 4

This version of ASP.NET MVC was released on August 15, 2012 and targets .NET Framework 4.0 and 4.5. Visual Studio 2010 SP1 and Visual Studio 2012 provide support to develop ASP.NET MVC 4 applications.
ASP.NET MVC 4 introduced the following key features:
  • ASP.NET Web API
  • Asynchronous Controllers with Task support
  • Bundling and minification
  • Support for the Windows Azure SDK

ASP.NET MVC 5

This version of ASP.NET MVC was released on October 17, 2013 and targets .NET Framework 4.5
and 4.5.1. Visual Studio 2013 provides support to develop ASP.NET MVC 5 applications.
ASP.NET MVC 5 introduced the following key features:
  • ASP.NET Identity
  • ASP.NET Web API2

5. Architecture of ASP.NET MVC Application

The basic architecture of an ASP.NET MVC application involves the following components:
  • The MVC Framework
  • The route engine
  • The route configuration
  • The controller
  • The model
  • The view engine
  • The view
Each  of  these  preceding  components  communicates  to  process  requests  coming  to  an  ASP.NET  MVC application. The process of handling an incoming request involves a series of steps that the components of the ASP.NET MVC Framework perform. These steps are as follows:
  1. The browser sends a request to an ASP.NET MVC application.
  2. The MVC Framework forwards the request to the routing engine.
  3. The route engine checks the route configuration of the application for an appropriate controller to handle the request.
  4. When a controller is found, it is invoked.
  5. When a controller is not found, the route engine indicates that the controller has not been found and the MVC Framework communicates this as an error to the browser.
  6. The controller communicates with the model.
  7. The controller requests a view engine for a view based on the data of the model.
  8. The view engine returns the result to the controller.
  9. The controller sends back the result as an HTTP response to the browser. 
Share on Google Plus

About Hà Tuấn Anh

2 nhận xét: