What are the key differences between ASP.NET webforms and MVC - asp.net

I know what MVC is and I work in webforms but I don't know how MVC will be that much different. I guess the code behind model will be different. So will it be like webforms minus the code behind and instead having it in a controller?
I see there are other related posts but I don't they address this.

For starters, MVC does not use the <asp:control> controls, in preference for good old standard <input>'s and the like. Thus, you don't attach "events" to a control that get executed in a code-behind like you would in ASP. It relies on the standard http POST to do that.
It does not use the viewstate object.
It allows for more intelligent url mapping, though now that the Routing namespace has been spun off, I wonder if it can be used for WebForms?
It is much easier to automate testing of web parts.
It allows for much easier separation of UI logic from the "backend" components.

The image says it all.
Update: Adding the original link for completeness.
http://forums.asp.net/t/1528396.aspx?MVC+vs+Web+Forms

The video tutorials here help describe the differences.

There is so much that can be said about your question.
MVC allows for clean separation of concerns, testability, and test driven development (TDD). It supports clean RESTful URLs and is very extensible... meaning you could swap out of the viewing engine, the routing mechanism, and many other things that you might not like out of the box.
For additional information I would suggest reading Dino Esposito's blog post entitled An Architectural View of the ASP.NET MVC Framework. Inside this post he compares many differences between the classic code behind approach with MVC.

Asp.Net Web Forms:
Asp.Net Web Form follows a traditional event driven development
model.
Asp.Net Web Form has server controls.
Asp.Net MVC model:
Asp.Net MVC is a lightweight and follow MVC (Model, View, and
Controller) pattern based development model.Asp.Net MVC does not
support view state.
See more..

Related

Confusion on using asp.net or mvc

Ive been confused about ASP.NET MVC.
As some said, MVC is better than ASP.NET. As some said, they are completely the same thing.
And my colleges debate that MVC is just an extension of asp.net, where asp.net is already in the form of MVC.
In fact I am starting web developing from scratch. If someone might help to clear the fog front of me, it would help a lot.
All ASP.NET web frameworks are build on top of Microsoft ASP.NET Framework. The unique feature of Web API is that it can be used with both MVC and WebForms applications to provide truly restful HTTP services.
Regarding the choice of suitable Asp.NET framework: you may get more information from official source - www.asp.net.
General rule of thumb is the architectural design how you want to build your application.
ASP.NET MVC promotes a cleaner separation which makes the developer think more in depth about design and code separation than traditional web forms.
There are endless debates about what is better but true benefits of ASP.NET MVC as
testability
more control over the rendered HTML
separation of concerns. However with MVC there is much more to learn for the developer.
ASP.NET WebForms - will always be around because some see it as a rapid application development tool. Just drag and drop and let ASP.NET handle the posting, state etc
ASP.NET Web API - is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
All in all, each of them has certain business solutions to be considered as required.
References to look for comparison:
ASP.NET MVC vs WebForms: speed and architecture comparison
ASP.NET Roadmap: One ASP.NET – Web Forms, MVC, Web API, and more
ASP.NET is the name of the overall web framework. There are a few different technologies that are built on ASP.NET. Two popular examples of these technologies are WebForms and MVC.
WebForms promotes a programming model that looks a lot more like Windows Forms. It attempts to abstract away the stateless nature of the web, and encourages you to use server-side controls instead of HTML. Because WebForms was the primary way to write web applications on ASP.NET for a long time before MVC came out, you'll often see people talk about "ASP.NET" as the same thing as WebForms. This is part of the reason for your confusion. ASP.NET WebForms is very different from ASP.NET MVC, but they are both built on ASP.NET.
ASP.NET MVC gets away from server-side controls. It eliminates the abstractions, allowing you to have closer control over the actual HTML that gets generated. For developers of modern applications, this is very useful because it makes it much easier to use AJAX and rich client-side javascript.
(Humble Opinion incoming)
ASP.NET (in terms of using Webforms) is programming the web for a WinForms developer. You "bind" events, you have "controls" and everything (sessionstate) is stored in a huge hidden field within the page so it knows where it left off from the previous call. You rely heavily on this information being present which is why everything you do needs to reside in that master form wrapping the entire page.
On the other hand, MVC is bringing C# .NET programming back to the web the way the web was intended. No bloat, no hidden fields, no heavy bindings. It's brings everything back to the classic "i have this form and now I need to process it". Arguably, the real magic is the routing methods and the "automatic binding" of submitted fields to an object. (if fields x, y & z are submitted and your action is looking for FooBar with the properties x, y & z it's automatically converted for you.
ASP.NET is common to both WEB-API and ASP.NET MVC. I assume you wonder about MVC or WEB-API.
MVC is a controller / model based with Views. Although the controllers can be used for AJAX json purposes. MVC is a good way to build a serious Browser based Application. The WEB-API allows you to build simple http server features, not necessarily Browser related. Good for REST style programming. Very flexible and a good alternative to WCF services. The are good tutorials on Both on the official ASP.NET site. START here http://www.asp.net/get-started
choose depends on your project n you. I suggest you to choose MVC because its productivity is very high we r using it since 1 year and found better than webforms.
for more knowledge please visit http://www.asp.net/mvc
The choice depends completely on you, I have been developing MVC application since 2010, its going to be over 2 years now have worked with almost all the versions of MVC both with Razor and aspx view. I have also worked on ASP.Net webform based applications.
With MVC you will not get built in controls, you will have to develop every control you want to use, you will have to rely mostly on html controls, while with web forms you will get advantage of using built in controls, Even getting help from other developers in your surroundings may be easy for webforms as you can easily get a webform developer.
But on the other hand with MVC the maintability is very high. As for as productivity is concerned, its very high once your are accustomed to it, initially it will be low as you will be in learning phase. Don't forget to use Entity Framework.
You may also consider developing your App using WebAPI, if it suits your scenario.

Does asp.net MVC depends on Normal asp.net

this is my first question Here ,
I am a beginner in asp.net , and i want to make a CMS project using it
After Some readings I found that the MVC structure is very suitable for Me
Just want to know :
how much the asp.net MVC depend on the normal asp.net??
as a beginner i don't know the level of knowledge for Normal asp.net to start working using asp.net MVC
Please tell me where to start in the normal asp.net(3.5) and when to switch to learn the asp.net MVC ??
Detailed information is very welcome
Thanks For your Time
It is built on normal ASP.NET minus postbacks, viewstate, and event wiring. The underlying System.Web stuff is the same, but with some new wrappers to access it, and of course a bunch of new featuers that make up the MVC portion. Just get a book on ASP.NET MVC, and don't worry about classic ASP.NET.
'normal' (also known as WebForms) asp.net and 'mvc' asp.net are somewhat different from each other in how things are put together and how things work with each other. There is no need to learn one before learning the other.
If you read through this article you can see at a glance what the differences are between 'normal' or WebForms and 'mvc'.
Here is a pretty good tutorial for learning about MVC from Scott Guthrie if this is the way that you're leaning.
Good luck and have fun!
It depends on what you mean by "ASP.NET". ASP.NET MVC does depend on standard ASP.NET request processing pipeline (IHttpModules, IHttpHandlers and all other internal workings), but it does not depend on WebForms infrastructure.
I've recently jumped on the ASP.NET MVC bandwagon and I found the introduction tutorials on the official http://asp.net/mvc site very useful.
ASP.NET WebForms tried to mimic WinForms desktop apps in that you have controls and event-driven interaction, which is not particularly well suited to the stateless HTTP
ASP.NET MVC gives you full control over the HTML that is generated and sent back to the browser, but more importantly, it makes it easier to write testable code.
Also, ASP.NET MVC does not depend on ASP.NET WebForms, they are built on the same foundation. In fact, in principle, you can mix and use both in the same app if you really wanted to :)
When MVC was released, what used to be simply ASP.NET was renamed ASP.NET Webforms and MVC because ASP.NET MVC. Not sure if that answers your question but it does clear up some terminology.
Why not start with Asp.Net MVC ?
Asp.Net is split now into 2 parts. Webforms and MVC.
I'd advise looking at the following -
http://bloggingabout.net/blogs/mischa/archive/2008/02/04/asp-net-mvc-vs-asp-net-webforms-vs-ruby-on-rails.aspx
http://nerddinner.codeplex.com/

How is the best method to generate a url with ASP.NET?

I will apprecaite your help in this topic.
I need to build a site with friendly urls using url rewriting in order to improve SEO positioning.
I've been searching torought web and finally pointing to this two main options :
asp .NET with isapi extension
asp .NET mvc
however, I got no experience on both items so I need you to help me to kwow further about this two technologies and to take the right decision for my needs.
Thanks
There are much bigger concerns than just URL setup when making this choice. You're talking about two completely different architectures for building your web pages.
You should make the decision on how you want to build your application, what skillsets you have available in your developers, etc. Both approaches will be able to handle the URLs that you need to generate for SEO considerations.
For public facing websites, I would personally choose ASP.Net MVC, because I find the development cycle shorter, more productive, more flexible and more maintainable than an ASP.Net webforms application.
Assuming you have a host/server that can run ASP.NET MVC (i.e. one that has the .NET Framework 3.5 Service Pack 1 installed on it), you can use the Routing Engine (System.Web.Routing) from ASP.NET MVC in a web forms environment, Phil Haack has a good updated walkthough at "Using Routing With WebForms".
There's also "How to: Use Routing with Web Forms" on MSDN.
Unlike an ISAPI filter, this enables you to use the routing engine to generate your internal links as well as responding to well formed links from outside.
I agree with womp. But there is one advantage i see in Asp.Net webforms that Asp.Net Mvc doesn't have: Rich Client Iteraction controls. Everything in Mvc in View layer is simple and functionality need to be build from scratch.
alexserver - at the same time of course, the fit between mvc and jquery is an overwhelming reason to abandon the rich clinet controls. that way, you can literally get your designer and/or a jquery UI expert to work on the view portions in isolation whilst you craft the model and controllers.

Is ASP.NET MVC a bad choice for a large enterprise project?

We are about to embark on a large enterprise application. I am seriously considering using ASP.NET MVC because:
We need to use Microsoft technology (biz logic is all C#)
Performance is critical
I'd like to test as much as possible
My team has only used PHP for web development, but are very experienced with .NET winforms (so either way we have a learning curve). My concern is that some people have expressed concerns about ASP.NET MVC's scalability to large apps. But from what I read webforms have their own problems as well.
Should I be reconsidering webforms, or stick with my gut and use ASP.NET MVC?
Related:
Should I build my next web app in ASP.NET MVC?
https://stackoverflow.com/questions/521388/from-webforms-to-asp-net-mvc
ASP.NET webforms are heavyweight and drop a crapton of stuff on your webpages, both in html/javascript and serialized viewstate. I remember my first ASP.NET website causing the GC to blowed up because of all the short-lived objects being rehydrated from that godawful viewstate. Oh, when I was young and naive (i.e., 2 years ago)... You have to have a very good understanding of webforms to build scalable websites from them. Possible? Definitely. Easy? Not.
ASP.NET MVC is harder to code initially, but is SO much easier to develop than webforms. The hardest things to learn are 1) the conventions aka "magic strings", 2) Html + inline code aka ASP and 3) html forms.
With MVC, you can't get away with the state nightmare that is so common to webforms development, which means that means your webpages are meth-addict slim. It also means you have to code your state a little smarter. The code is also MUCH simpler and scales MUCH better than traditional webforms, imho.
Also, testing with ASP.NET is near impossible, due to the hard-coded and unmockable dependencies baked into the framework. ASP.NET MVC replaced all of these with System.Web.Abstractions members that are mockable wrappers around these badly-designed and untestable objects.
Run, don't walk, to MVC.
For the obvious-impared, if you use a framework that sits ontop of the ASP.NET framework, such as MVC or any other that you wrote or that somebody else wrote, OBVIOUSLY some of these remarks don't apply.
If, on the other hand, you code as early man did against the ASP.NET webforms model (e.g., Response.Write() in Page_Load), my comments apply.
Can you write code that's testable against ASP.NET? Sure. Can you do it without including special testing code you or somebody else wrote? Sure. If you have TypeMock.
ASP.NET WebForms is very much like Winforms and allows for RAD (rapid application development). It's very fast to get something in no-time. Problem with this is testing can be a major pain and if used for anything public facing can mean some major issues with ViewState. WebForms can hold state making things like a wizard a breeze to use.
ASP.NET MVC on the other hand can take a little longer to develop with and requires that devs understand how HTTP works. It's a stateless architecture meaning each request is it's own little world and usually has no knowledge of previous requests. The framework also allows for high testability.
As far as performance goes they're probably the same because ASP.NET MVC is just a framework built on top of the existing ASP.NET architecture. Though for client-side experience I'd say MVC is a bit faster.
As far as scalability I would say they're about the same as far as technical goes. How as for using the API and integrating it MVC would probably be a bit easier.
The website you're using right now to ask this version question is built on ASP.NET MVC and they have 2 web servers and a beefy db server.
ASP.NET MVC is not a problem for Enterprise, but neither is ASP.NET, Silverlight, etc. They are all UI technologies. The majority of your application logic should exist in libraries beneath the UI layer anyway, so pretty much any UI can be used.
We need to use Microsoft technology
Performance is critical
I'd like to test as much as possible
Based on the above, ASP.NET MVC will work. But, you can move the code down below the UI and test. If your algorithms are below the UI, you can tune them without altering the UI. And, if the UI layer is very thin, the perf hit for the UI is negligible.
No. One thing that the ASP.NET MVC has over ASP.NET Web Forms in terms of performance is that it doesn't make use of a control tree. The control tree consumes a lot of server side memory and keeps the garbage collector very busy on pages with many controls. I would argue that you would get superior performance from the ASP.NET MVC. The unit testing aspects of it are a real win to.
The flip side of this is that you can't use all of the handy out of the box controls that you get with ASP.NET Web Forms and you'll probably end up doing more client side JavaScript development so the initial development budget would probably need to be greater if you choose ASP.NET MVC over Web Forms, but you would have a superior solution for the long term.
Stick with your gut. ASP.NET MVC helps facilitate testing because almost the entire API derives from interfaces.
Have used WebForms for years and never liked them. Now use Asp.Net MVC for some years and this is so much better. Certainly woud recommend MVC.
Asp.Net MVC has an excellent architecture and is open source. So if you would identify bottelnecks in the http processing chain you could fix it. Most time you would be able to fix performance issues using one of the many extension points provided by Asp.Net MVC, like Binders as an example.
I would say go with MVC if you need or want its features . If you are building a line-of-business application such as an ERP or CRM system, I would use Webforms; if you are building a portal or community wiki type site I would go with MVC hands down. Ultimately it comes down to preference and what exactly your enterprise application needs to accomplish.
"With MVC, you can't get away with the state nightmare that is so common to webforms development, which means that means your webpages are meth-addict slim"
Upmodded for that quote!
My opinion: use ASP.NET Webforms.
Disable ViewState in the Web.Config.
There is no need to preserve state because everything you really need is in the Request object.
Use Javascript in conjunction with AJAX for data retrieval to render your UI controls client-side.
Create serverside wrappers in the form of control tags for your client-side component renderer.
This is how I've been working for ages now, and it's fast, reliable, testable and organized.
It does take some time to setup a decent framework for this working method, but eventually it will rule.
I rather have no spaghetti code like MVC. Been there with PERL/PHP and classic ASP.
Everything I've read about asp.net MVC says that it is able to serve up more page requests than asp.net webforms.
I have some doubts about its stability and security though. Both of these stem from the fact that it's not even released and even with the RC we saw some changes to the framework. I am sure there will be more changes as time goes on and things are found. It's new so there are not really "best practices" out for it and there is a not a wealth of experience out there detailing the small issues or gotchas that you might run into.
I've been using it and it does result in smaller pages and faster performance. But there are so many things I can do in webforms that I have no idea how to do with mvc because mvc does not promote the use of the webforms controls.
If you're able to use stored procedures then you don't need a big middle-tier like those generated by MVC. All you have to do is pass XML to your stored procs through a simple HTTP handler, get results back from a stored proc, and convert the results to JSON. MVC and other middle-tier stuff only serves to make money for companies that sell IDEs like VS.

ASP.net: What type of application/website is more suitable to Webform or MVC?

I have read all the post regarding the pro and con of ASP.net webform vs mvc.
However, I'm wondering under what circumstance does one use webform or mvc? would it come down to what you or your team is more familiar with?
Typical business application with lots of controls, their behavior rules, with enabling/disabling them in response to the events fired by other controls would be a lot more complicated task with MVC while with WebForms you can do it during a coffee-pause.
Also with MVC you get nice SEO-friendly urls out of the box, which is great for publicly exposed sites. WebForms do not offer that convenience, however, for internal applications or the public ones protected by customer login it is no concern at all.
As time goes by, I find it very hard to use WebForms (against mvc) for anything new.
My opinion is asp.net webforms more suitable for application that use it in intranet (internal systems) because it have a bunch of controls. also if you implement a big Application.
Asp.net MVC Suitable for a websites that uses a lot of ajax and you want a SEO frindly urls.

Resources