Comparison between MVC and webform

Source: Internet
Author: User
Tags ruby on rails

When a foreigner's original article is translated, it is as follows:

What are the shortcomings of ASP. NET web forms?

 

The traditional ASP. NET web forms is a very good idea, but the actual needs are very complex. Over time, real-world projects expose some shortcomings of web forms:

 

"Heavy" view Status: In reality, maintaining status between HTTP requests (called view status) leads to huge data block transfer between the server and the client. In typical cases, this data block will be several hundred kb in size, and the data block will be transmitted back at each request, resulting in a decrease in the access speed of website visitors, it also increases the bandwidth burden on the server.

 

Page lifecycle: As part of the page lifecycle, the mechanism for connecting client events and server event processing code is sometimes complicated and subtle. Few developers can successfully manipulate the control hierarchy at runtime without view status errors. Sometimes, some event processing code may fail mysteriously.

 

Limited HTML control: server-side controls convert themselves into HTML tags on the client, but they are often not what you want. In ASP. in versions earlier than net 4.0, its HTML output is usually not in line with web standards, and does not have a good combination with Cascading Style Sheets (CSS, in addition, the server control automatically creates unpredictable and complex tag ID values, making JavaScript inaccessible. These problems are solved in ASP. NET.
4.0, but it may still be tricky to get the expected HTML Tag.

 

Problematic Abstraction: web forms tries to hide HTML and HTTP implementation details as much as possible. When you want to implement custom behaviors, you must jump out of this abstraction frequently, force you to reverse engineer the implementation of the callback event mechanism, and take some tedious methods (obtuse
Generate the HTML text you want. These abstractions can even bring frustrating setbacks to experienced web developers.

 

Low-level testability: ASP. NET designers do not take automatic testing as a necessary tool for this software development platform. It is not surprising that the tightly coupled architecture they designed is not suitable for unit testing, and integration testing is also a problem.

 

ASP. NET is evolving. Version 2.0 adds a set of standard application components to reduce the amount of code you need to enter. The Ajax version released in 2007 is Microsoft's
2.0/ajax crazy popular response, which supports rich client interaction. The recently released ASP. NET 4.0 version can generate most foreseeable HTML tags that comply with standards, but many of its inherent limitations still exist.

Main advantages of ASP. NET MVC

 

 

 

ASP. NET has achieved great commercial success, but as mentioned above, other web development platforms are constantly moving forward. Although Microsoft has been trying to remove the "Spider Web" on web forms, its internal design concept is outdated.

 

In March, at the first alt. Net Conference held in Austin, Texas, Microsoft vice president Scott Guthrie released and demonstrated a brand new MVC Based on ASP. NET.
The web development platform is clearly designed to respond directly to technologies like rails, and also to the industry's Criticism of web forms. The rest of this chapter describes how this new platform solves the various deficiencies of web forms and brings ASP. NET back to its peak.

 

(1) MVC Architecture

 

It is very important to clarify the differences between the MVC construction mode and the ASP. net mvc framework. The MVC pattern is not a new thing-it goes back to the Smalltalk project at Xerox's Palo Alto Research Center in 1978-why is it so popular in today's web development field:

 

The user interaction of MVC applications conforms to the natural cycle: the user executes an action. In response, the application changes its data model and provides users with an updated view. The application has been running cyclically. This mode is very suitable for Web application Transfer

 

A series of HTTP requests and responses.

 

Web applications must involve several different technical fields (databases, HTML, and executable code). These technologies are usually distributed across different layers. The concept of MVC naturally corresponds to the combination of these technologies.

 

The ASP. net mvc framework implements the MVC mode, which facilitates better separation of attention. In fact, ASP. net mvc implements a special MVC pattern customized for Web application development. In Chapter 4th, you will learn more about the theory of this system and experience it yourself.

 

Through the inclusion and improvement of the MVC model, ASP. net mvc framework is more competitive than Ruby on Rails and has also introduced MVC to mainstream. Net fields. By using the ASP. NET
According to the MVC experience evaluation and feedback from practical applications, ASP. net mvc has surpassed rails in many aspects.

 

(2) scalability

 

Your desktop computer is made up of independent parts, which are connected by standard, public, and documented interfaces. You can easily replace your video card and hard disk with the products produced by another manufacturer, and make sure they can be inserted into the corresponding slot and work properly. The principles of the MVC framework are the same as those of PCs. They are built on a series of independent components, such as a trusted one. net interfaces or user classes that inherit abstract base classes-you can easily replace these components with your own implementations, such as routing systems, view engines, and controller factories.

 

The ASP. Net MVC designer provides three options for you to use every component of the MVC framework:

 

Implement with default components (enough for most applications)

 

Inherit from the default implementation to implement a subclass to fine-tune certain behaviors

 

Replace these components with new interfaces or abstract base classes

 

These look a bit like the Provider Model in ASP. NET 2.0, but it goes further-completely into the core of the MVC framework. From Chapter 2, you will understand various components and understand why you want to adjust or replace them.

 

(3) Strict control over HTML code and HTTP (tight control over HTML and HTTP)

 

ASP. net mvc knows how important it is to generate neat and compliant tags. The output of its built-in HTML helper method fully complies with the standard, but more important changes compared with web forms are reflected in its design philosophy. In the past
Forms automatically generates a lot of disgusting encapsulated HTML tags with little control. As an alternative, the MVC Framework encourages you to use CSS to design concise and elegant tags.

 

Of course, if you want to put some gadgets with ready-made composite UI elements on your page, such as calendar or cascading menus, Asp. the "no Special Requirements" flag method in net MVC allows you to easily use the best UI library, such as jquery or Yahoo's Yui library. Microsoft has built jquery into ASP. NET
Part of the default MVC Project template, JavaScript programmers will. net MVC is so tightly integrated with the popular jquery library that you can directly reference jquery even on Microsoft's own content delivery network (CDN) server. JS file. We will cover jquery in Chapter 20th.

 

Pages generated by ASP. net mvc do not contain any view status data. Therefore, they are hundreds of KB smaller than typical ASP. NET web forms pages. Although today's broadband connections are already very fast, this bandwidth saving will still bring huge experience improvements to end users.

 

Like Ruby on Rails, ASP. net mvc and HTTP work in harmony. You have full control over requests between the browser and the server, so that you can fine-tune your user experience according to your preferences. Ajax is easy to implement now, and there is no automatic sending back that affects the client status. Any developer who pays attention to the web development field will almost certainly find that ASP. NET
MVC can greatly reduce the workload and make the tasks completed in the same time more satisfactory.

 

(4) Ease of testing

 

MVC makes you a huge step in application maintenance and testing, because you can naturally separate the functions implemented by the program into many different and independent software blocks. However, ASP. net mvc designers are not satisfied with the end. To support unit tests, they introduced the concept of component-oriented design in the framework and ensured that each separated code block was built to meet the needs of unit testing and simulation tools.

 

For developers, they also added the create unit test wizard in the Visual Studio wizard, which can use many open-source unit test tools, such as nunit and xunit, even Microsoft's own mstest. Even if you have never written unit test code before, you will have a good start.

 

In this book, you will see many of them as ASP. net MVC controller and action are simple and simple unit test examples. These examples use various testing and simulation policies to impersonate the implementation of framework components, to determine any situations that may occur during actual operation.

 

Ease of testing is not only reflected in unit testing, but also works well between ASP. net mvc applications and UI automated testing tools. You can write a test script in a simulated user interaction scenario, without having to guess the structure of the HTML element, the CSS class used, or the ID to be generated by the framework, there is no need to worry about the inexplicable changes in the page structure.

 

(5) Powerful Routing System

 

The URL style is also evolving along with the development of Web application technology. Like the following URL:

 

/App_v2/user/page. aspx? Action = show % 20 prop & prop_id = 82742

 

It will gradually become scarce and will be replaced by a simple and neat format, as shown below:

 

/To-rent/Chicago/2303-silver-Street

 

There are several good reasons for paying attention to the URL structure: first, the search engine assigns a large weight to the search keywords in the URL. Searching for "Chicago rent" makes it easier to match the simple URL above. Second, many network users can understand the meaning of a URL, and they appreciate the smart navigation options when entering an address in the browser address bar. Third, when people understand the structure of a URL, they are more likely to link it, share it with friends, or even read it out loud on the phone. Fourth, it will not disclose the technical details, directories, and file names of your applications to the entire Internet. Therefore, you can change the underlying implementation without affecting your existing connections.

 

It is difficult to implement precise URLs in earlier frameworks. However, ASP. net mvc uses the system. Web. Routing namespace by default to easily provide precise URLs. It allows you to control the style of your url and associate it with your application, providing you with the freedom to create meaningful and useful address styles for users, the predefined mode is not required. In addition, you can easily define a fashionable rest-style URL style as long as you want. You will see a Detailed Routing Scheme and the best URL exercises in Chapter 2.

 

(6) building on the best part of the ASP. NET platform

 

Microsoft's existing ASP. NET platform has provided a mature and tested set of components and tools for developing practical and efficient web applications.

 

First, it is also the most obvious, because ASP. net MVC is built in.. NET platform, so users can flexibly use any.. NET Programming and accessing the same API functions-not only in MVC, but also a large number of systems. net class library and the vast third-party.. Net Library.

 

Second, the existing ASP. some functions of the. NET platform-such as master pages, form verification, membership, roles, profiles, and internationalization-can reduce the amount of code you need to develop and maintain any application, these functions are equally effective in the MVC framework, because they are originally an outstanding Web
Forms project. You can continue to use some of the web forms built-in server controls in the ASP. net mvc project, as well as the custom controls you created in the early ASP. NET project. (However, you cannot rely on the web.
Special concepts in forms, such as view status)

 

Development and deployment alternate. ASP. NET is not only closely integrated with Visual Studio, but also as a native web programming technology for Windows
Internet Information Service (IIS) installed in XP, Vista, 7, and server operating systems is supported. After iis7 is released, it will host the native part of the request processing pipeline of the Code in. Net to provide it with first-class support, which is also a special treatment of ASP. NET. Because MVC applications are based on the core of the ASP. NET platform, they will also enjoy these benefits. Chapter 2 describes how to deploy the MVC application in IIS on a Windows server.

 

(6) Modern APIs

 

Since Microsoft launched the. NET platform in 2002, it has been continuously developing, supporting or even defining the top level of modern programming technology.

 

ASP. net MVC is designed. net 4.0, so its API can use the latest programming language and all the benefits of runtime innovation, including extension methods, lambda expressions, anonymous and dynamic types, language integration query (LINQ ). The API methods and coding modes of many MVC frameworks are as neat and expressive as possible than those of earlier platforms.

 

(7) ASP. net mvc is open-source

 

Unlike Microsoft's previous platform, you can download and even modify the original ASP. net mvc code and recompile it into your own version. When your debugging footprint goes deep into a system component and you want to step through its code (or even read the original author's comments), open-source code is very useful. It is also helpful if you want to build a more advanced component to see what may happen or observe how the built-in components work.

 

At the same time, if you do not like the implementation of some work, or you find an error, or you want to access something that is not accessible in other ways, the open-source benefits are very powerful. Because you can simply change it.

 

However, if you upgrade your framework to a new version one day, you need to repeat your changes and apply them again. ASP. net mvc was released according to Microsoft Public License (MS-Pl, http://www.opensource.org/licenses/ms-pl.html), an open source license approved by the Open Source promotion organization. That is to say, you can modify the source code and deploy it, and even publish it to the public as a derivative project. However, Microsoft does not accept any patches on its official version. At this stage, Microsoft only maintains the code of the product development and quality assurance team. You can download the MVC source code from the http://aspnt.codeplex.com/website.

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.