ASP. net mvc and ASP. NET WebForm, asp. netmvcwebform
ASP. net mvc is a WEB development framework of Microsoft. It integrates the efficiency and cleanliness of the "Model-View-controller" architecture and is the most modern idea and technology of agile development. It is a perfect alternative to traditional ASP. NET WebForm.
1. Today's Web Development
1) REST (Representational State Transfer) has become the main architecture for applications to operate on each other over HTTP, completely eclipsing SOAP. REST describes an application based on the resources (URIs) that represent real-world entities and the standard operation methods (HTTP methods) that are available on these resources.You can perform corresponding operations on resources by combining the HTTP method and resource address. This combination is REST. The requests that execute such operations are also called restful requests. (The personal understanding of REST is still not thorough and will be supplemented later)
Currently, Web applications not only provide HTML services, but also XML or JSON data, which is difficult to support by WebForm.
2) The entire software industry is moving towards agile and test-driven development, such as unit testing tools (NUnit, xUnit), imitation frameworks (Moq, Rhino, Mocks) control and reverse container (Ninject, AutoFac), continuous Integration Server (CruiseControl, TeamCity), object relation CER (nhib, Subsonic, EF, Dapper, Petapoco), and UI automation tools. (Test-driven development TDD idea: first, describe the desired behavior example, known as the test specification, and then conduct software design, so that by executing a set of tests attached to this implementation, to verify the stability and correctness of the application.)
3) comply with the Web standards and restful trends.
2. History and problems of ASP. NET WebForm
Shows the technical stack of ASP. NET WebForm:
This figure indicates that WebForm is built on ASP. NET, and ASP. NET is built on the. NET platform. The role of MVC framework is to replace WebForm.
WebForm is designed to make Web Development feel the same as Windows Form development. Developers no longer need to work with a series of independent HTTP requests and responses. They can think of it as a stateful UI. People can forget the WEB and Its stateless nature, instead, we use a drag-and-drop designer to create the UI and imagine that everything happens on the server.
Over time, WebForm has some defects in actual projects:
1) view status overload: the actual mechanism for maintaining the status, that is, ViewState, which leads to transmission of large data blocks (up to several hundred KB) between the client and the server ), in addition, the response time is slow because it is between requests, increasing the bandwidth demand of the server;
2) page lifecycle: The mechanism for connecting the client and server event processor code is complex and difficult to maintain during application running;
3) incorrect idea of focusing on separation: it is a good way to extract code from HTML and put it into the background code class for processing, however, some developers mix the presentation code and application business logic in the background code, resulting in final code confusion and difficulty in maintenance;
4) Restricted HTML control: the Server Control renders itself into HTML, but it is not the expected HTML. CSS cannot be used well before ASP. NET 4. At the same time, unpredictable or complex IDs are generated, making it difficult to access JavaScript.
5) flawed Abstraction: WebForm tries to hide HTML and HTTP as much as possible (implemented through the abstract layer of WebForm ). When you implement your own method, you need to discard this abstraction and force reverse engineering to adopt the callback event mechanism. Therefore, this abstraction poses a huge obstacle and challenge for developers;
6) Low testability: This tightly coupled architecture of WebForm is not suitable for unit testing and is also challenging for integration testing;
3. ASP. net mvc features
1) ASP. net mvc framework implements the MVC mode (the MVC mode was proposed in 1978. net mvc greatly improves attention separation, so it is particularly suitable for Web applications. The interaction with MVC applications follows the natural cycle of switching between user actions and views. In this cycle, we assume that the view is stateless. This is very consistent with the HTTP request and response methods supporting Web applications.
2) Scalability: the MVC framework is built into a series of independent components, such as the routing system, view engine, and controller factory. You can easily replace these components with your own implementations, there are usually three options:
A. Use the current default implementation of components, which can meet the needs of most applications;
B. derive a subclass of the default implementation to adjust its behavior;
C. Use an interface or a new implementation of the abstract base class to completely replace the component;
3) Strict control over HTML and HTTP. ASP. net mvc will generate neat and standard compatible tags. Its built-in HTML helper method can generate standard-compatible output. Pages generated by ASP. net mvc do not contain any ViewState data. This bandwidth saving greatly improves user experience and controls the requests transmitted between the browser and the server.
4) testability: ASP. net mvc applications can not only perform unit tests, but also cooperate well with the UI automated testing tool.
5) a powerful Routing System Using a REST-style routing solution has the following benefits:
A. The search engine has an obvious weight on the keywords found in the URL. For the same keyword search, it is very likely to switch to a relatively simple URL address;
B. Many Web users have a good understanding of the URL and are willing to enter the URL address in the address bar of the browser;
C. After understanding the structure of a URL address, people are more likely to link it and share it with others;
D. This URL structure does not expose the technical details, folders, file names, and other structures of the application to the Internet. The underlying implementation can be freely modified without damaging the link;
6) built on ASP. NET platform, on the one hand ASP. net mvc is based on.. NET platform, so you can use any. NET platform flexibly.. NET language to write code, can be widely used. NET class library and a large number of third-party.. NET class library system; on the other hand, ASP.. NET platform features, such as authentication, members, roles, configuration files, and internationalization, can reduce the amount of code required to develop and maintain Web applications.
7) ASP. net mvc is. NET 4. x, so its API can take full advantage of current language and runtime innovations, such as await keywords, extension methods, lambda expressions, anonymity, dynamic types, and LINQ.
8) ASP. net mvc is open source.
4. Comparison between ASP. net mvc and ASP. NET 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 must replace the latter, nor does it mean that the latter will die out.
- The concept of WebForm is that the UI should be stateful. The result is that an abstract layer is added over HTTP and HTML, and ViewState and Postback are used) to create a stateful effect. This is a "drag-and-drop" Windows Form style development.
- MVC adopts the true stateless nature of HTTP. The MVC Framework requires you to understand the actual way Web applications work, and maintain and expand them on the premise of understanding them, it provides a powerful, simple, clean, and modern way to write Web applications and get rid of complicated restrictions.
- Therefore, to develop small and enterprise internal applications, you can consider using WebForm. But more often, when developing Internet applications or large applications, MVC is a better choice for efficiency, compatibility, and maintainability.
Reference: proficient in ASP. NET MVC X