Follow me to one of ASP. NET MVC: a good opening

Source: Internet
Author: User

Summary:

ASP. NET MVC is Microsoft's Web development framework, combining the effectiveness and cleanliness of the model-view-controller (MVC) architecture, the most cutting-edge ideas and technologies of agile development, and the best parts of the existing ASP. It is a complete alternative to the traditional ASP. NET Web form. In this article, I'll show you why Microsoft has created ASP. NET MVC, which is different from his previous technology.

Asp. NET history

To understand the history of ASP, you need to understand the history of ASP. Asp. NET was created in 2002. He combines ASP. NET WEB Form Technology, ASP.

Through Web Forms, Microsoft hides HTTP (and its stateless) and HTML by modeling the user interface (UI) into a series of hierarchical server-side control objects (many developers are unfamiliar with him at the time). Each control maintains and records its own state during an HTTP request, renders itself as an HTML element when needed, and automatically connects client events (such as button events) and the corresponding server-side event handler code. In fact, Web Forms is a large abstraction layer designed to send a classic event-driven user interface (GUI) on the web. His idea was to make web development feel like Windows Form development. Developers do not need to handle a series of interdependent HTTP requests and responses. They just need to care about the UI logic, and Microsoft seamlessly delivers the Windows desktop developers ' armies to the Web application world.

Asp. NET disadvantage

    • view state burden: The actual maintenance state mechanism between cross-request States (view states) results in large data transfers between the client and server side. The transmitted data can be up to hundreds of KB in a very simple web, and travels back and forth in each request, resulting in very slow response times and increased bandwidth requirements for the service side.
    • page life cycle: the mechanism for connecting client events and server-side event handler code (part of the page lifecycle) can be unusually complex and granular. Few developers are able to successfully handle and control hierarchical relationships at run time without getting view state errors or to discover that some event processor processors have failed strangely.
    • faulty separation of concerns : the ASP. NET Web form code-behind model provides a way to separate application code from HTML markup. This way of separating business logic and performance has been widely welcomed. However, in reality, developers are encouraged to combine presentation and application layer code together into the same weird code-behind class. (for example, the server-side control tree will be processed and the code that processes the database). Lead to fragile and incomprehensible results.
    • Limited control over HTML: The server-side control renders itself as HTML, but not necessarily the HTML you want. Earlier versions of ASP, HTML output did not conform to web standards, the use of cascading style sheets (CSS) was not good, and the server-side controls produced unpredictable complex ID attribute values that were difficult to access using JavaScript. These issues have improved a lot in the recent Web Forms release, but you will still get the hard-to-handle HTML you expect.
    • the abstraction of a crack appears: Web forms tries to hide HTML and HTTP whenever possible. When you implement customer behavior, you often give up this abstraction, forcing you to use the event mechanism in turn or use a dull way to produce the HTML you want. By this time, all Web Forms abstractions have become a frustrating barrier for web developers.
    • Low testability: Web forms designers did not anticipate that automated testing would become an important component of the software development process. Not surprisingly, the tightly coupled architecture they designed is not suitable for unit testing. Integration testing is also challenged.

Web forms is not all that bad, Microsoft has made a lot of effort to improve his flexibility, simplifying the development process, and even taking some features from ASP. Web Form is better when you need to develop quickly (a relatively less complex web app can be developed in one day). But unless you are very careful in your development, you will find that the applications you create are very difficult to test and maintain.

Main benefits of ASP.


In October 2007, Microsoft announced a new MVC development platform, built on the ASP. NET core platform, designed to adapt to innovative technologies such as rails and the direct response of Web Form critics. The following section describes how the new platform overcomes Web forms and how to bring the ASP back to the edge of the era.

It is important to differentiate between MVC schema patterns and the ASP. NET MVC framework. The MVC pattern is not something new-back to 1978 at Xerox PARC's Smalltalk project-but now as a model, he has gained a huge welcome in Web applications. There are several reasons:

    • MVC architecture

The user interacts with the MVC application in a natural loop: the user issues a behavior, changes its data model as a response system, and sends an updated view to the user. Then repeat the loop. This is very handy for sending a series of HTTP requests and receiving a response to a Web application.

Web applications force a combination of technologies (such as databases, HTML, and execution code) to separate them into different tiers. The patterns generated from the process of combining these layers naturally map to the MVC concept. Asp. NET Framework implements the MVC pattern, which improves the separation of concerns in the implementation process. In fact, ASP. NET MVC implements quite a portion of the MVC pattern, especially for Web applications.

    • Scalability

The MVC framework is built on a series of separate. NET interface-based components, and is based on an abstract base class. You can easily replace components, such as replacing routing systems, view engines, and controller factories with different components that you implement yourself. Presumably, the MVC framework gives you three options:

    1. Use the default standard components (sufficient for most applications)
    2. To replace the default component behavior with an inherited class
    3. Replace the default component with a new interface-based and abstract class component

Tightly control HTML and HTTP

Asp. NET produces clean, standard markup HTML. Based on the HTML helper class method, the output conforms to the standard, but there is a more philosophical change than the Web Forms. Instead of creating a HTML,MVC frame that you can't control, you are encouraged to write simple and elegant markup that is decorated with CSS.

Of course, if you don't want to throw away some of the complex UI element widgets that are readily available, such as date controls or hierarchical menus, ASP. NET MVC is easy to use the best UI frameworks such as the jquery UI or the bootstrap CSS framework.

The pages generated by ASP. NET MVC do not contain any view state data, so they are smaller than the pages generated by the ASP.

ASP. NET MVC works seamlessly with HTTP. You can control the requests that are passed between the browser and the server, so you can control your user experience in as little detail as possible. Ajax has become very easy, without any automatic callbacks from the client to the server-side interface.


Testability

The MVC architecture lets your application start to be maintainable and testable, because you naturally detach different application concerns. However, ASP. NET designers did not stay here. To support unit testing, they made the framework design a component-targeted design, ensuring that each separate section was able to serve the needs of unit testing and mocking tools.

Testability is not just a unit test. An ASP. NET MVC application can also work well with UI Automation tests. You can write a test script that mimics the user's actions without worrying about which HTML element, CSS class, or framework generated the ID, and you don't have to worry about any changes in the HTML structure of the page.

A powerful routing mechanism

With the update of Web application technology. The URL style also changed. A URL like this:

/app_v2/user/page.aspx?action=show%20prop&prop_id=82742

are getting smaller and fewer. be replaced with a simpler and cleaner format below:
/to-rent/chicago/2303-silver-street

There are some good reasons to care about the structure of URLs. First, search engines value keywords found on URLs. Search for "Rent in Chicago" is more likely to appear in search. Second, many web users now understand URLs enough to be able to enter URLs directly at the address. Third, when people start to understand the URL structure, they are more likely to link him, share it with friends, and even read it aloud on the phone. Four, he doesn't expose the technical details, folders, and file names of your application.

Clean URLs are difficult to implement in previous frameworks, but ASP. NET MVC uses a feature called URL routing to provide the default clean URLs. This allows you to control your URL pattern and the relationship with your app. It gives you the freedom to create meaningful URLs that are useful to your users without having to obey a well-defined pattern. Of course, this means that you can easily define a style of the URL that you would prefer for a stylish rest style.

Built on the best part of the ASP.

Microsoft's existing ASP. NET platform provides a proven, validated set of components for developing efficient and efficient web applications.

First, most obviously, because ASP. NET MVC is based on the, you can use any. NET language to access the same API features-not just MVC itself, the. net extension class framework and the vast third-party. NET Framework ecosystem.
Second, the already-well-done features of the ASP-such as authentication, membership, roles, profile, and internationalization-can reduce your code when developing and maintaining the web system, and these features are as effective in the MVC framework as in the classic Web Form project. Asp. NET platform provides a rich collection of web development tools for the MVC framework.

ASP. NET MVC is open source
Unlike the previous Microsoft Web development platform, you are free to download ASP. NET MVC source code, and even modify and compile your own version.



Follow me to one of ASP. NET MVC: a good opening

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.