What is ASP.
ASP. NET is a Microsoft's Web application framework built on Common language runtime for building dynamic WEB sites using O NE of the programming languages like C #, vb.net etc. It supports 2 models Web Forms and ASP.
What is Web Forms?
Microsoft first brought out ASP. NET Web Forms from ASP which solved lots of problems by creating higher level abstraction Over stateless the web and simulated stateful model for Web developers. In Web Forms concepts like self postback (post form data to same page) and ViewState (maintain control values during POSTB ACKs) is introduced. And the most interesting part is it's not required to write even a single line of code. With web Forms Microsoft tried-bring the Visual Basic model into Web.
Let's talk about advantages and disadvantages of Web Forms.
Advantages:
(1) Web Forms supports Rich server controls.
- While working with the pure HTML you might has noticed, things is not always same at any place.
A UI which looks great in IE might distract in Firefox or vice versa.
The ASP. NET server control detects the browser and generates appropriate HTML and if required JavaScript also.
- Many server controls like the GridView and ListView comes up with data binding capabilities reducing lots of efforts and codes Being written.
(2) Support forViewState
You might has heard couple of times "HTTP is a stateless protocol". Normally controls would not retain their values between requests. But in Web Forms statefulness are achieved by storing last known state of every control within the client page itself in th e form of hidden field called ViewState.
(3)Event driven programming
With the help of
-
- Code behind
- Self postback mechanism (posting back form to the same page)
- ViewState
Microsoft introduced event driven programming in the Internet world.
Developer'll no more rely on POST, GET methods for handling user interactions with server. For example she/he would drag control (say button) to page, just double click it to generate the code block for handling US Er ' s click on Server, write down the logic inside it. That ' s it. She/he isn't concerned with what happens inside.
(4)Rapid application Development
I don ' t think any explanation are required for this. Rich server controls, Event driven model and ViewState increases the development speed by great extent, Developer'll be Abstracted from lots of the background complexities.
(5) Lesslearning effort
Using Strong server controls and ViewState developer can develop real world applications with minimal HTML and JavaScript Skills.
Disadvantages:
(1)Project Architecture
There is no fixed predefined Project Architecture for creating Web applications when it comes to Web Forms. Developers has full flexibility for choosing their own architecture.
One may use basic three layered architecture dividing the system into UI, business layer and Data access layer or a more a dvanced one like Model-view-presenter. Even one may choose only code behind and write everything there which are not in all considered as good practice. Code behind is tightly connected to UI, ending up with some presentation logic.
(2)Unit testing
In Web Forms code behind ends to lots of event handlers, making automatic unit testing an impossible task.
Note: as per my knowledge even with the "help of" mock testing (using MOQ or RHINOMOQ) we can ' t mock ' sender ' an d ' EventArgs ' in event handlers.
And when we talk about employing TDD, unit testing code behind (presentation logic) becomes very important.
(3)performance
ViewState becomes solution for some problems with classic ASP is it also becomes an issue. ViewState is stored on the page itself resulting increased page size so reduced performance.
(4)reusability
- Let's talk about another example where we're supposed to build 2 UI
- Taxable Employee Screen
- Nontaxable Employee Screen
Now, most of the code behind logic was going to being same for both screens.
One solution'll is, add some if conditions in code behind and create a single UI.
- This would violate single Responsibility principle which says there should is only one reason a software entity to be Chang Ed, because in this case employee form is changed whenever any of the taxable/nontaxable information changes.
- Secondly it may possible that both UI
- Less Control over HTML
In Web Forms many times we aren't sure about what HTML we'll get on the end making integration with JavaScript Framewor KS like JQuery a difficult task
URL ' s is pointing to fixed ASPX pages which might is decorated with some query string. They is not user friendly and affect SEO.
(5) Less support for parallel development -ASPX page is tightly coupled with code behind files. So it's not possible 2 different developers is working on one section (one on ASPX and one on code behind) at same t Ime.
ASP. 4.0
ASP. 4.0 have come up with some good features to overcome some of the above problems
- ViewState: Provide the disable or control the size of the ViewState. (But there was no compulsion or fixed rule that would say to does so.)
- URL Routing: Using URL Routing We can provide our own URLs in lieu of the physical path of the page.
- ID: In ASP. 4.0 We have better control over the Id of elements and thus integration with JAVASCRIPT framework become easier. (We still don ' t has complete control over HTML being generated.)
Even after the evolution of the revolutionary features of ASP.
- It is still not able to solve the problems of unit testing
- I never saw any ASP. Web Form developer who tries to disable the ViewState. (It ' s my perspective, no hard feelings.)
- We got some control over the ID of elements, but not the complete control over HTML, still has problem to implement JavaScript.
What is MVC?
MVC is a architectural pattern which is have been around for sometimes now.
Many is using it including Java. It's not a new concept which Microsoft brought it up. ASP. NET MVC is something we should talk about. But prior to that lets clear some terminologies including MVC.
- Patterns- in simple words Pattern was a solution to a problem in a context.
- architectural Patterns- architectural Pattern is something which solves we problem at Sub Syst EM level or at short module level. It deals with the problem related to architecture of a project. It tells us how we can divide our systems and especially. We make Class libraries, components, WEB services to solve the problem.
- MVC when We talk about application we'll be have have input logic, business logic and UI logic an D MVC is a architectural pattern which let us develop an application have loosely coupling between each of these elemen Ts. The
the main intention behind MVC pattern is separation of concerns. It makes presentation or UI ignorant of business and user interaction logic. The
according to MVC system should is divided as M (Model), V (View) and C (Controller).
|
- Model is considered as smart and handles the business rules, logic and data and would be independent of other parts of MVC (Controller and View).
- Controller receives and dispatches the request in short it handles the user interaction and input logic. It knows about both Model and View.
- A view is considered as dumb and are an output representation of model data. The It may is a Excel sheet, a Web page showing list of records or just a simple text. View knows about the only Model.
|
What is ASP. NET MVC?
ASP. NET MVC is a Microsoft's one more WEB application framework designed with separation of concerns and testability in MI nd. It is built on the CLR and completely based on MVC architecture and so we think in terms of controllers and views. ASP. NET doesn ' t has support for ViewState and server controls, so we get feel of the old web here. Let's talk about advantages and disadvantages of ASP.
Advantages:
- Project Architecture-
|
One of the advantages of using ASP. NET MVC is it enforces separation of concerns. So there are very less chances of getting things more complex. |
Test Driven Development and reusability
- in MVC Controller is a separate CLA SS so automatic testing is possible featuring Test driven development.
- Controllers is bound to any specific view and so can is reused for multiple views
. |
- Performance -ASP. NET MVC don ' t have the support for view state, so there'll not is any auto Matic state Management which reduces the page size and so gain the performance.
- Full Control over HTML -ASP. Net MVC doesn ' t support server controls, only option available is U Sing HTML input controls, so we'll be sure on the final HTML rendered at the end. We'll also is aware about ' id ' of every element. And so integration of the ASP. Application with the third party JavaScript libraries like the jQuery becomes easy.
- support for parallel development -in ASP. NET MVC layers is loosely coupled with One developer can work on Controller, at the same time and third developer on Model. This is called parallel development.
- SEO, url Routing and REST -Rich routing features lets treat every URL as a resource supporting RESTful interfaces.
Also user-friendly and readable URL improves SEO.
- Extensibility- ASP.NETMVC supports multiple view engines like ASPX, razor and if required we can create our own.
- Existing ASP. features– ASP. NET MVC framework is built on top of matured ASP. NET Framework and thus provides developer to use many good features s Uch as forms authentication, Windows authentication, caching, session and profile state management etc.
Disadvantages:
- More learning effort- Absence of event driven programming model and ViewState makes ASP. A very difficult framework for developers with N O or little experience in Web application development.
How ASP. NET MVC Works
- User makes the request for some resource in server (by putting some URL in the browser).
- request comes to controller first (routing engine is the one of the one who are responsible for deciding which request would be Han Dled by which controller. In this article we won ' t talk in depth about this behavior).
- Controller if required talk to model for data.
- Model operates on database (or-some other data sources) and return data (in form of business objects) to controller .
- Controller chooses the appropriate view (like say Customer view which would may contain some HTML tables, drop downs, T Extboxes ...).
- Controller passes the data (model data retrieved in step 4) to chosen view (in step 5), where data would be populated as Per convenience.
- Controller sends back view to the user.
This is for GET request, same happens for post. Only instead of putting URLs in the browser user would do some action on already requested page and flow start with the Cont Roller. Actions like clicking button, changing drop down value etc.
Why ASP. NET Web Forms and why ASP?
Each can is the ' best choice ' for a particular solution depending on the requirements of the application and the Backgroun D of the team members involved. What to choose and when have have more to do with business prospective than which one are better than other. When facing a decision to choose between ASP. Web Forms or ASP. NET MVC It's important to know that neither technology is meant to replace the other.
Important factors you should consider and making the choice is
- RAPID application development-if you want to develop anything rapidly ASP. Web Forms is the only chance your is Havin G, you can ' t even consider for ASP. (Reasons for Rad could anything like client was not paying too much, O R application is going to being used for only one or both months and won ' t require much maintenance.)
- Unit TESTING-IF Automatic Unit testing is the most important factor for you MVC would be the best for you.
Other than these, what are you can do are, write down all your project requirement and try to compare them with Pros and Cons O F both Web Forms and MVC and if possible try to ask yourself following questions and point MVC and Web forms accordingly
- Does your team has good experience with Web forms or Windows forms?
Well, if yes then probably learning ASP is going to be a tedious task for team, because developers has been used To with ViewState and event driven programming by now and migration are going to bes a difficult task.1 point to Web Forms.
- Does your team has good experience with ASP.
IF Yes ASP. NET MVC Get 1 point
- Does your team has experience on ASP or Non-microsoft technologies such as Android, iOS, JSP, ROR, PHP?
If you have been JSPs or ASP developer Prior then you might is familiar with HTTP get and Post and even u might has hands On with MVC because most of the them use MVC by default. It gives 1 point to ASP.
- Is JavaScript going to be used extensively?
If Yes, MVC gets the point because you get complete control over HTML. 1 point ASP.
- Looking for good performance?
With the no support for ViewState ASP. NET MVC provides good performance gain over traditional ASP. NET MVC.
- Planning to reuse the same input logic?
If Yes stick with MVC.
Conclusion
I Think you should has equipped with enough information-a decision what's best for your project. The complete decision depends on your team and project requirement.
Hope all of your enjoyed reading this article. Thank for the patience.
For technical training related to various topics including ASP, Design Patterns, WCF and MVC contact[email Protect Ed] or at www.sukesh-marla.com
For more stuff like this click here. Subscribe to article updates or follow at Twitter @SukeshMarla
Also go through our complete step by step series of MVC (Model View Controller)
Click here for See MVC Video step by step.
Transferred from: Http://www.codeproject.com/Articles/528117/WebForms-vs-MVC
WebForm vs MVC