Project both webform mvc - asp.net

I have a project developed with WebForms while
I would like to continue the rest of developement with MVC. How i do that ??

Yes its possible,
you will required to do changes in web.config for handling ensuring both MVC & webforms works. thats one time setup you needs to complete.
there are many articles available online.
for eg. check https://www.codeproject.com/Articles/38778/ASP-NET-WebForms-and-ASP-NET-MVC-in-Harmony

Related

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.

ASP.NET MVC alongside Web Forms in the same web app?

Has anyone successfully deployed ASP.NET MVC alongside Web Forms in the same application in a production environment? Were there any conflicts or gotchas you faced while doing so?
Is it really as easy as shown here in practice? What about if you run a MVC using the Razor view engine alongside Web Forms?
Mvc is build on top of asp.net as is webforms, so yes it's easy.
Done it couple of times for conversion purposes
Maybe this url's could help you:
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
and
http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx
One gotcha is don't put your WebForms inside the Views folder. I haven't get figured how to make MVC leave those paths alone. None of the ignore routing instructions seems to work in this case and the WebForms throw 404s.
Other than that WebForms works perfectly fine alongside MVC since MVC2.
Has anyone successfully deployed ASP.NET MVC alongside Web Forms in
the same application in a production environment?
I never mixed ASP.NET MVC and classic WebForms in the same application. I make them run in separate applications and communicate between them with standard HTTP techniques (query string parameters, form posts, cookies, ...).
Is it really as easy as shown here in practice?
Yes, it is as easy as that.
Check out scott hanselmans AddMvc3ToWebForms nuget package. I am using it and its working pretty great. I am using it to gradually convert my web forms app to mvc
I've spent a lot of time over the past few months on this. Here are my observations.
The good/easy
- Getting Webforms to call into MVC controllers
- It was remarkably easy to stand up a new MVC3 project and drop Webforms pages into it.
- I was able to move my <pages><controls></controls></pages> section into the /pages directory in a new web.config there
The dirty/difficult
Regarding the GUID
Please note that the GUID has to be added at the front of the line for some reason... everytime I tried it failed. Until I stumbled on a post that insisted it be the before the others.
also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
getting the landing page to be Webforms caused ALL kinds of snags.
getting jQuery intellisense to play nicely with T4MVC
this is what I did to address that
#if (System.Diagnostics.Debugger.IsAttached)
{
<script src="../../Scripts/Mvc3/jquery-1.7-vsdoc.js" type="text/javascript"></script> #* intellisense! *#
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_js)
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_js)
}
else
{
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_min_js)
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_min_js)
}
Recommendations:
Use T4MVC in ALL cases even if you are pure webforms. The elimination of magic strings for static content (.js,.css, images, specifying templates) is outstanding.
and if you have any part of your build process compiling views then you get compile-time safety on any of those links.

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.

Can "classic" ASP.NET pages and Microsoft MVC coexist in the same web application?

I'm thinking about trying out MVC later today for a new app we're starting up, but I'm curious if it's an all or nothing thing or if I can still party like it's 2006 with viewstate and other crutches at the same time...
Yes you can have your webforms pages and MVC views mixed in a single web application project. This could be useful if you have an application that is already built and you want to migrate your app from webforms to mvc.
You need to make sure that none of your webforms pages go in the 'Views' directory in a standard ASP.NET MVC application though. Pages (or views) in the 'Views' directory can't be requested directly through the url.
If you are starting an application from scratch, there would be very little benefit to mixing the two.
Yes. MVC is just a different implementation of the IHttpHandler interface so both classic ASP.NET and ASP.NET MVC pages can coexist in the same app.
As you've probably noticed with the above answers, yes this is very possible to do.
I've actually had to do this on my current project. I was able to get approval to add MVC to our application, but only in the administration section (to limit the risk of affecting current members coming to our site).
The biggest problem I had was converting my Web Site to a Web Application, but once that was done, things were pretty straight forward adding MVC side-by-side our classic code-behind web pages.
The trick for me was to make my MVC pages look as similar as possible to my code-behind pages so the transition looked as seamless as possible.
I am currently working on a new project. While I would like to go down the MVC route all the way, some of the project requirements don't allow me.
One of those requirements is to have a grouping grid from the client-side. Personally have chosen the Telerik Rad-Grid. While they may be in the process of supporting MVC they are not there as yet.
So this means that I have to have a hybrid solution. for the time being until RadGrid fully supports MVC.
While we are in this transition period I think that there will be may more hybrid projects out there until the support of the Third Party Controls catches up.
Regards
Nathan
You'll need to make sure your MVC routes don't conflict with your Web Forms pages so that requests for a .aspx page don't get routed to a controller action as a parameter etc.
See this blog post by Phil Haack for details on how to avoid this.
Yes, it is very much possible for MVC pages to coexist with asp.net web forms. I implemented that in my existing asp.net application for adding new features. We need to make sure of referring the MVC DLLs, registering routing tables for URL routing and configuring the assemblies and namespaces in Web.config file.
If you're mixing MVC with other methodologies you're not really getting the benefit out of it. The point of MVC is to allow you to decrease coupling and increase cohesion, and if only half of your code is doing that, then the other half is inevitably going to restrain your development cycle.
So, I guess while it's possible, I don't think it's worth it. Go all the way or don't go at all.

Hybrid WebForms/ASP.NET MVC [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
ASP.NET MVC alongside Web Forms in the same web app?
I am kinda new to .NET applications, I have a web forms application that I am working on and I am about to start the development of new pages, I am trying to make the new pages with the ASP.NET MVC, but I am not beeing able to make the pages hit the controllers. First i added the library references added the routes on the global.asax but not sure what else is missing, can someone help me out?
thx.
Reading between the lines I gather you are trying to add MVC pages to your existing ASP.NET Webforms Webapplication?
If that is the case then you probably need some MVC specific config. settings. Easiest way is to create a new MVC web app and then merge the config settings.
Furthermore if you are doing a hybrid project I'd recommend giving Scott Hanselmann's post on the topic a read.
There's a more step-by-step description of adding MVC to a WebForms Application at these links:
Integrating ASP.Net MVC Into An Existing ASP.Net Web Application
Mixing ASP.NET Webforms and ASP.NET MVC
You might also want to add the ProjectTypeGuid to the project file with a text editor ({603c0e0b-db56-11dc-be95-000d561079b0} is used to designate to Visual Studio to use the MVC extensions.)
<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
The links above also don't fully cover the system.webserver area of web.config that needs to be configured.
Scott Hanselman released a "totally unsupported" Nuget package that adds MVC 3 features to an existing Web Forms project. It also works on my PC (ha ha) and I've used it on several projects.
http://nuget.org/List/Packages/AddMvc3ToWebForms
He blogged about it here:
http://www.hanselman.com/blog/CreatingANuGetPackageIn7EasyStepsPlusUsingNuGetToIntegrateASPNETMVC3IntoExistingWebFormsApplications.aspx
One newb tip: this package will configure your MVC routes in /App_Start/RegisterMvc3Routes.cs
I've spent a lot of time over the past few months on this. Here are my observations.
The good/easy
- Getting Webforms to call into MVC controllers
- It was remarkably easy to stand up a new MVC3 project and drop Webforms pages into it.
- I was able to move my <pages><controls></controls></pages> section into the /pages directory in a new web.config there
The dirty/difficult
Regarding the GUID
Please note that the GUID has to be added at the front of the line for some reason... everytime I tried it failed. Until I stumbled on a post that insisted it be the before the others.
also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
getting the landing page to be Webforms caused ALL kinds of snags.
getting jQuery intellisense to play nicely with T4MVC
this is what I did to address that
#if (System.Diagnostics.Debugger.IsAttached)
{
<script src="../../Scripts/Mvc3/jquery-1.7-vsdoc.js" type="text/javascript"></script> #* intellisense! *#
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_js)
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_js)
}
else
{
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_min_js)
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_min_js)
}
Recommendations:
Use T4MVC in ALL cases even if you are pure webforms. The elimination of magic strings for static content (.js,.css, images, specifying templates) is outstanding.
and if you have any part of your build process compiling views then you get compile-time safety on any of those links.

Resources