Comparison between ASP. NET and ASP. NET MVC

Source: Internet
Author: User

In fact, the website development architecture often referenced by Java/jsp can also be divided into Model 1 and Model 2. Model 1 can also be divided into two to three types, as shown below:
The first method is to mix HTML and. Net (Java) code, commonly known as pasta style writing, such as ASP. The most common problem with this Inline code is the low readability and difficulty in maintaining the program.

The second is to directly access the database by a code-behind code pair corresponding to. aspx, that is, a two-layer architecture. However, this disadvantage is that the program code is difficult to reuse, and because the logic has been written to a fixed page, it will cause difficulties for system expansion in the future.

The third type is to access the database or perform business logic operations (JSP + JavaBean) by using the custom class library and app_code data folder ). However, there is still a lack of unified control over the process. As a result, each aspx (JSP) must verify the user's identity, verify the request parameters, Process sessions, and handle exceptions, even the encoding principles and language sets in the view must be processed in the code-behind corresponding to each Aspx. Therefore, this is not suitable for the development, expansion, and maintenance of large systems. Although this architecture can also achieve a virtual three-layer or multi-layer architecture, it is also the limit of ASP. NET 2.0.

To Model 2, also known as the MVC Framework, the controller is added to control processes and events by the center. In addition to making the entire system operational process clearer, it can effectively cut down the work at each layer, and avoid the code-behind in the view to process database access and business logic operations in the model, you do not have to write the program code "process transfer and redirection" everywhere, but the central controller program code (Action method) is used for unified control.

However, the MVC Architecture also has its disadvantages. For example, developers need to take the time to switch concepts and learn frameworks, especially. NET developers or teams, because they didn't have the idea of unified controller coordination process in the past, they had to get used to it again and rewrite a lot of program code originally written to different pages into the controller. In addition, during the design phase, the system must first coordinate the formats and practices of data exchange between various types of objects. Therefore, it is necessary to lengthen the system's prior analysis and planning time. However, if a ready-made framework like struts or. net mvc framework can be applied, you can achieve twice the result with half the effort when developing large systems in the future.

 

 

Advantages of MVC:

1. It is easy to maintain during large-scale development and has good scalability.

2. You can have full control permissions on HTML, which is friendly to the front-end.

3. Ability to perform unit tests to ensure the implementation of functions.

 

Disadvantages:

1. There are not so many ready-to-use controls, and the development efficiency is relatively low (especially for cainiao)

2. It is difficult to process large data because there is no ready-made girdview control. Although the HTML structure generated by this control is extremely complex, it is very good for processing large amounts of complicated data. However, there are very few such massive and complex data on websites. Many cainiao use this cannon to attack mosquitoes, which is a waste and inefficient task. This control should not be recommended for website development.

 

The new cainiao and webform are good when rapid development is required.

Scalability is required. MVC is recommended for high control. However, the threshold for using this framework is relatively high. If you only understand the webform development form of Asp.net, because webform has already done too many things for you, in other words, you do not know what real web development is like. On the contrary, ASP users are more familiar with PHP.

 

MVC and webform have their own purposes.

However, you should not use the Asp.net MVC framework:

You are not very familiar with Polymorphism

You don't like building applications on this framework

You rely on many third-party UI controls

You do not like to use open-source programs

 

 

Reporter:What do you think is the biggest obstacle to enterprise-level Web development? How to use ASP. Net MVC Framework to relieve the pressure on programmers on this obstacle?

Yi Mingzhi:I used to have a video interview with me. I talked about some of this content, but some programmers may have misunderstood what I mean due to the title and partial expression. In fact, compared with ASP. net mvc 1.0, ASP. net mvc 2 has made so many improvements. What are the goals of improvement? To a large extent, it is to reduce unnecessary labor volume and potential risks and increase productivity, let developers focus more on business processing (the business I mentioned is not what the market Personnel said ). Therefore, the biggest obstacle for enterprise-level Web development is that developers waste too much energy on non-business core aspects, for example, data verification, UI code writing, and some tedious but technical aspects.

The new ASP. many new features of net MVC reduce the workload of developers, such as HTML. the editformodel method can directly generate a very good editing interface in the view, and has the ability to automatically identify: bool type attributes, corresponding automatically generate checkbox, enumeration type automatically generate a drop-down list, and so on. Controller, action, and filter all bring us a lot of similar automatic mechanisms, reducing a lot of tedious and tasteless work, so that we can focus more on our core work.

Through learning MVC, we can see that MVC has the following features:
1) Separation of business processing and display: The ASPX page is completely separated from the CS code. Better reuse and maintenance.
2) Form Controls on the server are no longer recommended. They are replaced by traditional input, or HTML. textbox is directly used to generate control labels.
3) No event-driven model is available. In ASP. net MVC, when a button is clicked, you should not habitually think of the corresponding Aspx. there is a click Processing Method in CS. You should think of an action in a controller to handle this event.
4) No data binding is available. If you are used to the data binding of the gridview, you need to change your mind in ASP. net mvc.
5) added address rewriting. The MVC routing component allows us to perform URL routing well.
6) in general, we can understand that MVC is a web form-based programming model extension and a presentation layer programming model solution.

 

The advantages of MVC work are obvious, which is more conducive to understanding the layered logic and grasping the Code's attention. The process from the Controller to the ASPX page has been isolated by the framework. As for the calling process of the controller, view page, and model, you still need to be sure. ASP. net mvc framework implements separate management of controller code.

Looking at the webform development model, it is only executed in the httphandler container and layered. It lacks support in big aspects and can only be logically separated. It does not mean that they cannot be separated, but by some limitations. The interception of httphandler is related to the access suffix. When a page is requested, it is a handler, And the webform model achieves display and logic separation, only the winform event-driven.

Obviously, events must be registered to pages, such as code such as button#click. The page_load method is executed before the button#click operation. When the display code is written to the page_load method, additional waste code needs to be written, such as if (! Page. ispostback. The part to be displayed after the execution of the button#click operation is more difficult to handle. Writing another method is also required to be called in the button#click operation. The alternative solution is to use response. Redirect to process the logic on An ASPX page. After the processing, the page jumps to another displayed page. The disadvantage of this is that it is difficult to share data between two pages, and the jump is achieved by marking 302, so one more request.

In addition, you can also use server. execute, server. transfer or context. if the rewritepath processing method is used, the two page transformations are completed on the server side and data can be shared. It can be said that the processing method of the two pages is similar to that of the MVC framework. The disadvantage is that you need to manually configure these retargeting attributes.

From the above analysis, we can see that the MVC framework has a strong advantage, and webform is not useless, and it is easier to develop in simple applications. Webform can also be implemented in the same way as MVC, but it only needs to write more code during processing. In my opinion, the biggest problem encountered when using webform to develop layers is the data transfer between pages. In my opinion, I have mastered the application skills (server. execute, server. transfer or context. rewritepath) development can solve the data transmission problem. webform development is easier to understand than MVC Framework, and does not produce complicated configurations. It is also a good choice.

Related Article

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.