The similarities and differences between Web Form and ASP-NET MVC architecture and development

Source: Internet
Author: User

The Web form referred to in this article refers to the framework for developing Web sites based on the. NET platform (which we often call "ASP."), and Web form is actually divided into two parts: Web Form (visual Interface) and ASP (background Web Component). All system.web.ui.* namespaces can be referred to as Web Form, which under the System.web.* namespace can be called ASP. NET was born in early 2002, Web form before the Microsoft Web Development technology has asp,asp the business logic and the slogan language (HTML) code in the page, Web form for the ASP developer is a new change, the Web The form moves most of the server-side code into a class file and uses dynamic server controls instead of HTML tags, and Web form not only separates the business logic from the slogan language code, but also provides a more powerful development platform: the NET Framework, which enables rapid development of WEB programs, such as the ability to drag and drop controls.

Although ASP. NET improves performance and improves the debugging experience, there are still many problems.
First, the parts of the Web Form system.web namespace are tightly coupled, and the Web form remains focused on the Web page, although the code can be ported elsewhere, but it is still difficult to separate the business logic from the user view, in the Web Form schema, Each site's URL is represented by a single physical file. aspx, and each page is tightly coupled to the page code class, the page cannot dynamically select its own binding class, the code class cannot render other views, and the code in the page code class is not likely to be unit tested.

Second, the management state and data are important to any program, but the communication of the Web program is based on the HTTP protocol, the HTTP protocol is a stateless protocol, and is a non-persistent connection, each request corresponds to a client request and a server answer. The Web server must process each request separately, so it is not possible to know the front and back messages requested by the client, so that the server and the client cannot make a valid session, and the stateless nature of the Web application makes managing state data very complex. For example: To achieve a multi-step user registration Web application is more than a single step registration to do a lot of work, if made from the next step can go back to the previous steps, the workload is to multiply, the increase in the workload is to record the status of the program. In order to implement stateful sessions in a stateless mediation, the Web Form introduces the concept of view state, where the view state stores the server's interaction with the client in the hidden domain of the page, and the view state makes it easy to interact with the client, but it contains data that can be bloated, consuming bandwidth, Even a simple page can be larger than 100KB in size.

Based on some of the disadvantages of web Form above and some other reasons, with the popularity of Ajax technology, ASP. NET Framework, a number of new Web development technologies have emerged:
There are currently three main ways of developing Web sites:
First: Using ASPX, server controls, C # technologies like this:
In this way to develop the server to do a lot of things, html generation, simple JS interaction, client authentication, and so on, all by the service side to deal with, all page generation and the logic of the interaction of all services to complete, the page and user interaction is usually not very friendly, such as: the submission of data often refreshes the entire page.

Second: page +ajax way:
This way the page simply renders the data, and the submission of the form is all in Ajax mode. The benefit of doing so can be the separation between the display logic and the data update logic, without entanglement, in this development mode, because the page is only responsible for the display of data, so as long as the business logic can be separated from the UI as much as possible, the project in the maintenance of a lot easier, the site developed in this way, Page and user interaction is much better, and will not affect the SEO, so more portal site adoption.
There is a primitive way to implement Ajax in ASP, which is to create a ashx, and someone would choose to create an empty aspx instead of ashx, and use ASPX to output just one HTML fragment.

Third: The pure Ajax network, in this kind of website, the service side because does not participate in the UI processing, the website can be just some static HTML file, moreover in the design page, as long as leaves some placeholder to be possible, the UI element all is generated by JS. Clients of this type of site typically choose a JS UI framework to support. This kind of interface will be more beautiful than the first two, and the user's experience will be more friendly. However, because the page is mainly generated by JS, SEO support is poor, and therefore, particularly suitable for some background class site projects.

In the second and third development methods listed earlier, if there is a suitable framework, will have a very important impact on development work, in the development of Ajax, Microsoft has introduced the ASP. NET AJAX framework, it can generate some JS proxy class on the server, Let the client's JS can directly invoke the service-side method. Although the frame was cleverly designed and perfectly matched with WebForm, it was only a pity that the framework was not popular. Later WCF through some configuration can also let JS to call, however, not many people like, perhaps because of the configuration of the trouble. When Microsoft later launched the ASP. NET MVC framework, some people began to exclaim: Ajax non-ASP. NET MVC framework is not available. Because the ASP. NET MVC framework can easily make JS to invoke a C # method, from then on, there is no need to "read parameters, call methods, write output" These tedious things, and no more complex configuration of WCF. Indeed, they did not solve the problem, and the ASP. NET MVC framework was well resolved.

Microsoft launched the ASP. NET MVC framework, the first edition released in 2009. ASP. NET MVC is a schema based on the MVC pattern (model-view-control), and the same point is that asp: the same as the ASP, they share the HTTP handlers (handler) and modules (module), The HTTP handler still works in the ASP. NET MVC pipeline, which in fact begins with an HTTP handler that handles external programs, simplifying the complex parts of Web form application development with ASP. While preserving the capabilities and flexibility of ASP. ASP. NET MVC has something in common with ASP. ASP. NET MVC is a new programming model, a completely different architecture that has the advantages of loose coupling, easy expansion, and high maintainability. Compared to the disadvantages of the above mentioned ASP, the ASP. NET MVC view is separate from the logic, and the URL is not based on the paging file but on the route, relying on the URL of the dynamic map external to the correct controller operation, and allowing the operation to dynamically specify the view to be displayed to the user. The server page becomes a simple view, which is just an HTML template that waits for the object to be passed by the controller, no longer has a postback event life cycle, and the focus of the data model, application logic, and data representation is clearly separated. Instead of discarding page view (view state), ASP. NET MVC can reduce page content, but it may increase the cost of background processing requests and database requests, rather than using cached session states. Web Form can only develop the entire page with a server-side control instead of using HTML tags, so the Web Form view relies on servers controls to render HTML code, and ASP. NET MVC is completely free of server control controls, so it requires developers to write more HTML code. The HTML code is rendered using the Razor syntax code, and HTML code is written using the HTML helper method (HtmlHelper), and the developer can invoke its method directly in the view.

The similarities and differences between Web Form and ASP-NET MVC architecture and development

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.