I have a large legacy web application written in a combination of classic asp and asp.net webforms. The client has agreed to rewrite the application and we have decided to use MVC4 but of course we don't have the time to stop support on the legacy application to build the new application.
Is there a way to put an new MVC4 wrapper application around the existing/legacy application so that parts of the legacy application can be ported to the new environment piece by piece?
this is pretty old question, but I ran across it so thought I'd try and help out. You can still use the .aspx pages within MVC4 by modifying the routing functionality of MVC. this link should help you get started: http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
Related
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.
Our website is implemented in ASP and Visual Basic.
I wish to add a few new pages to the site but I wish to do it in ASP .NET MVC with C#. Are ASP and ASP.NET compatible for the same website?
I've done a few ASP .NET MVC tutorials. What would I need to do to get a simple hello world project to work on our server? What will I need to install etc?
Also, our database is implemented for sql server 9.0. Will there be any issues here?
Thanks,
Barry
Are ASP and ASP.NET compatible for the same website
The same IIS Web Application can include both ASP and ASP.NET pages.
But nothing will be shared, Session and Application objects are completely separate. To share code it will need to be COM components, and use the .NET tools to create a wrapper.
SQL Server 9.0
That's 2005: fully supported in .NET.
Adding a few bits to the Richard answer:
Create a MVC app and copy over all the asp files
Edit the global.asax and add the following line in RegisterRoutes
routes.IgnoreRoute("{resource}.asp/{*pathInfo}");
If the root of the site will continue to be an ASP file you have to deal with the routing also
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.
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).
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.