mix-up WebForm and MVC in one project vs separate them in 2 projects in the same solution - asp.net

I've tried to mix up WebForm and MVC in the same application, but so far I've failed miserably. It looks like I'm missing some steps some how some where. I'm really tired.
I wonder if just it's bad prectice to have 3 projects in a solution: The first one for the Model, the second one for the Webform, and the last one for the MVC.
Thanks for helping

If you have two separate projects one for MVC and one for classic WebForms it's like you have two distinct web applications. Those two should be deployed separately in different virtual folders in IIS.
On the other hand you have the possibility to mix classic WebForms and ASP.NET MVC in the same project.
Usually people have some legacy WebForms application that they want to migrate in ASP.NET MVC. But due to the sheer amount of code this cannot be done at once so you would create a new ASP.NET MVC application and import the existing legacy WebForms inside it which could be directly used. Then you could progressively update legacy code to the MVC pattern.
But from personal experience I find it dirty mixing classic WebForms with ASP.NET MVC. My hands just feel dirty. What I do is that I would keep legacy WebForms as a separate application and start replacing different sections of it with a new ASP.NET MVC application and the two of them would communicate only through standard HTTP techniques (usually GET and POST verbs).

Related

How to use ASP.NET MVC Master Pages Solution in Individual ASP.NET MVC Projects

We have an ASP.NET MVC project to serve as a master portal. The portal has links to controllers/views in other ASP.NET MVC projects. When the link is clicked, we want to a view from a different MVC project is loaded into the body of the master portal.
We know ASP.NET MVC provides Area within the MVC project to organize related functionality into a group functions. But instead everything in a project, we prefer to have related functionality into a separate project but they share the same master portal.
Is it doable within ASP.NET MVC and how?
Depend on what is your exact requirement,
If you want to share only data between projects expose controller
actions and share the data by means of JSON.
Sharing UI between project may not come handy in the long run.
Before anything, have a look at this article
Always there is way to do everything in programming, but consider performance and best practices to keep your application long living.

New ASP.NET project

When creating a new web project in ASP.NET are you better off to use the "ASP.NET empty web application" or the "asp.net web forms application"
I would recommend against even bothering with ASP.Net Web Forms. It was an interesting idea that proved to be unweildy in practical applications. The entire web development industry is moving towards some kind of MVC framework or another whether you're using PHP, Ruby or ASP.Net so you're best off using that.
Of course there are still a lot of ASP.Net Web Forms applications out there and they're likely to exist for some time into the future so there is some benefit to learning the technology but I would avoid it for any new projects.
As per your question if you should use the empty project or not it doesn't really make a difference. If you're just starting out the populated project can give you a basic idea of how the structure works but if you're comfortable enough building it from scratch then go with the empty project.
It depends on what you want to do.
Generally speaking, there are three kinds of ASP.NET application project:
Web Forms - what ASP.NET was originally back in 2001. Its use is discouraged in modern and greenfield applications because it is built-around outdated ideas about how web applications should work.
MVC - The new hotness. Try to use this. StackOverflow is built using this.
Everything else - too many to list, but this generally requires you create an empty project and do everything from scratch using IHttpHandler.
If you're new to ASP.NET I strongly recommend avoiding the two project types you listed as they're both for Web Forms; consider using the "ASP.NET MVC Application" options instead - if you're using VS2008 then you need to download and install the ASP.NET MVC 2 add-on. VS2010 and later come with the MVC templates preinstalled.
You might want to use the Empty Web Application project template if you want to work from scratch using IHttpHandler, but you sound new to this, so I recommend avoiding it.

Migrating from ASP.NET WebForms to ASP.NET MVC

I'm developing a web application for a company which I work for. My team started working on the app few months ago and the decision was to build it with ASP.NET WebForms. Now we've quite a lot of the code developed and we're wondering if ASP.NET WebForms was a good choice. Maybe we should migrate. Ok, but what's the first step? We don't want to rewrite everything from scratch. We'd like to add a new stuff in MVC and rewrite the old part in the future (gradually). Is it possible to add somehow ASP.NET MVC application to current WebForms one? Can they live together?
Asp.net webforms and MVC can live happily together. You will add some includes and directores and add a route which will cause your webforms pages to be ignored. All explained here:
http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc
Mixing MVC with webforms is not that all hard. Basically, you want to ignore any exisiting .aspx routes in your global.asax, and then add routes for new pages that you want to build using MVC.
See this article for more details.

Ideas to improve/enrich a WebForms application by adding ASP.NET MVC elements to it

I'm currently present with the following situation.
We have a huge enterprise application written with WebForms. Refactoring it or completely rewriting it is out of the question. So I'm not talking about migration WebForms -> MVC.
However, I understand one can technically add MVC functionality to coexist with the rest of the project. I was asked to present MVC concepts for a team so that we can consider how it could become (or not) of use to us.
After careful thinking I do not see any ways or reasons to add MVC elements to a WebForms project since it will become a strange breed then.
Maybe there are certain not exactly obvious possibilities to add value to a WebForms project with MVC framework? Has anybody thought about it?
Sharing a master between MVC and WebForms - dealing with the
Mixing ASP.NET Webforms and ASP.NET MVC
ASP.NET MVC WebForms Hybrid application
Combining MVC and WebForms from Pro ASP.NET MVC Framework (also available here)
I would also look at this article from Scott Hanselman. He seems to have the mojo on mixing these technologies.
Plug in Hybrids...Mixing ASP.NET and ...

Asp.Net MVC Areas, how can I use them?

I've got two questions about Asp.Net MVC areas. I have only a shallow understanding of areas from what I've heard about them in various podcasts but I think I understand fairly well what they're supposed to be used for. Now my question is if I could also use them to enable me to gradually switch from development in Asp.Net webforms with VB to Asp.Net MVC with C#.
Can I mix areas of different languages in one application, for example one area is a C# project and another is a VB.Net project.
Could I use the areas feature to incorporate MVC into an existing webforms application? Lets say I have a Asp.Net webforms application but I want any new "pages" to be written using MVC, could I create a new MVC project and then "jack it in" as an area into the existing webforms application?
In response to your questions:
Yes. If it's a separate assembly, then it won't matter if it's in c# or VB.net.
I'd say yes - it will help to keep your MVC stuff separate, but of course you will need the basic bootstrap stuff in your base webforms project. Good idea.
I've recently started introducing MVC into an older webforms site, and it's well worth the effort.

Resources