ASP. NET MVC and ASP. WebForm

Source: Internet
Author: User
Tags representational state transfer

ASP. NET MVC is a Microsoft Web development framework that integrates the efficiency and cleanliness of the "model-View-controller" architecture and is the most modern idea and technology for agile development. It is a perfect alternative to the traditional ASP. NET WebForm.

1. Today's web development

1) REST (representational state Transfer) has become the primary architecture for applications to interoperate on HTTP, completely tarnished by soap. Rest describes an application based on the resource (URI) that represents the real-world entity and the Standard action method (HTTP method) that is available on those resources. The combination of the HTTP method and the resource address allows you to perform the appropriate operations on the resource, which is rest, and the request to perform such an operation is also called a restful request. (The understanding of rest is not a thorough one, but this concept is supplemented later)

The current Web application does not just provide HTML services, it often requires XML or JSON data to be provided to the user, and WebForm is difficult to support.

2) The entire software industry is moving toward agile and test-driven development, such as unit testing tools (NUnit, XUnit), mock-up frameworks (Moq, Rhino, Mocks), control reversal containers (Ninject, AUTOFAC), Continuous Integration Server (CruiseControl, TeamCity), Object-relational mapper (NHibernate, Subsonic, EF, Dapper, Petapoco), and UI Automation tools are available. ( test-driven Development TDD thought: first describes the desired behavior paradigm, called the test specification, and then the software design, so as to verify the stability and correctness of the application by executing a set of tests attached to this implementation )

3) conform to the trend of web standards and rest.

2. The history and problems of ASP. WebForm

The technology stack for ASP. WebForm, as shown in:

The implication of this figure is that WebForm is built on ASP. NET, and the MVC framework has the effect of replacing WebForm.

WebForm's design idea is to make web development feel the same as Windows Form development. Developers no longer need to work with a series of separate HTTP requests and responses, which can be thought of as a stateful UI that lets people forget about the web and its stateless nature, instead using a drag-and-drop designer to create the UI and assume that everything happens on the server.

Over time, WebForm has some flaws in the actual project:

1) View state load: The actual mechanism of maintaining state, that is, ViewState (view state) causes large chunks of data to be transferred between client and server (up to hundreds of KB), and the response time between each request is slow, which increases the bandwidth requirement of the server;

2) page life cycle: The mechanism for connecting client and server-side event handler code is complex and difficult to maintain during application operation;

3) Focus on the concept of separation: it is a good way to extract code from HTML itself and put it in the background code class, but some developers mix the performance code with the application business logic in the background code, which leads to the final code confusion and difficult to maintain;

4) Limited control of HTML: server controls render themselves HTML, but not the HTML you want to see, and before ASP. NET 4, it doesn't work well with CSS. Unpredictable or complex IDs are generated at the same time, so JavaScript is difficult to access.

5) Flawed abstraction: WebForm attempts to hide HTML and HTTP as much as possible (this is achieved through the abstraction layer of WebForm). When you implement your own method, you need to abandon this abstraction and force the reverse engineering of the postback event mechanism. So this abstraction poses a great obstacle and challenge to the developer;

6) Low testability: This tightly coupled architecture of the webform is not suitable for unit testing and is challenging for integration testing;

3. Features of ASP.

1) the ASP. NET MVC Framework implements the MVC pattern (the MVC pattern was introduced in 1978), and since ASP. NET MVC greatly improves separation of concerns, it is especially useful for Web applications. Because the interaction with the MVC application follows the natural cycle of user action and view alternation, it is assumed that the view is stateless in this cycle. This is consistent with the way HTTP requests and responses support Web applications.

2) extensibility, the MVC framework is built into a series of independent components, such as routing systems, view engines, and controller factories, and you can easily replace these components with a different implementation of your own, usually with three options:

A, using the current default implementation of the component, which can satisfy most applications;

B. Derive a subclass of the default implementation to adjust its behavior;

C, a new implementation of the interface or abstract base class to completely replace the component;

3) with tight controls on HTML and HTTP, ASP. NET MVC produces neat and standard-compliant markup, and its built-in HTML helper method can produce output that is compatible with standards. The pages generated by ASP. NET MVC do not contain any ViewState data, and this savings in bandwidth can greatly improve the user experience and control the requests that are passed between the browser and the server.

4) testability, ASP. NET MVC applications can be not only unit tested, but also work well with UI Automation testing tools.

5) Powerful routing system with restful routing scheme has the following benefits:

A, search engine URL found in the keyword has a clear weight, the same keyword search, it is likely to turn to a more simple URL address;

b, many web users now have enough understanding of the URL, and are willing to enter the URL in the browser address column;

C, when understanding the structure of the URL address, people will be more likely to link it, and to other people to share;

d, this URL structure does not expose the application's technical details, folders, file names and other structures to the Internet. The underlying implementation can be freely modified without breaking the link;

6) built on the ASP. ASP. MVC is based on the. NET platform, so you can use any. NET language flexibly to write code, you can use a wide range of. NET class libraries and a large number of third-party. NET class library systems, and on the other hand, the features of the ASP, such as authentication, membership, roles, configuration files, Internationalization can reduce the amount of code needed to develop and maintain Web applications.

7) ASP. NET MVC is built for. 4.X, so its APIs can take advantage of current language and runtime innovations such as the await keyword, extension method, lambda expression, anonymous, dynamic type, LINQ.

8) ASP. NET MVC is open source.

4. The comparison between ASP. NET MVC and ASP. WebForm

The first thing to note is that although ASP. NET MVC has some advantages over ASP. NET WebForm, it does not mean that the former should replace the latter, nor does it mean that the latter will perish.

    • The WebForm idea is that the UI should be stateful, with the result that an abstraction layer is added on top of HTTP and HTML, with view state (ViewState) and postback (Postback) to create a stateful effect. This is a "drag-and-drop" type of Windows Form-style development.
    • MVC incorporates the essence of HTTP's true stateless nature. The MVC framework requires users to understand how a Web application actually works, to maintain and extend it in understanding, and to provide a powerful, simple, neat, and modern way to write Web applications and get rid of complex constraints.
    • So, developing small, enterprise-internal applications can be considered webform, but more often, when developing Internet applications or large applications, MVC is a better choice for both efficiency, compatibility, and maintainability.

Reference: Proficient in ASP. NET MVC X

ASP. NET MVC and ASP. WebForm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.