Merging ASP.NET Web Forms into ASP.NET MVC

we have asp.net web forms web site and asp.net MVC web site, and wanted to merge both into single web site so that we will be having single app pool at IIS.

most of the articles saying, the best way is to rewrite the asp.net web forms into asp.net mvc and then achieve the above requirement. But, there is often no business case for this when the application is well established and has grew over time to be quite a monster.


Below are then steps i just did




  1. Once setup, I copied the sub-folders and files from the corresponding top-level folder in Windows Explorer and pasted them into the solution. If you do it the way, the project allows you to copy in sub-folders and content directly, adding existing item via visual studio only copies in files thus saving time. Please note: for the root folder, I did NOT copy in web.config or Global.asax, but copied in all other files (like default.aspx, etc)
  2. Once all content was copied, I opened up web.config in the mvc web site project and web.config in the existing asp.net web forms web site. I copied the not existing tags into the asp.net mvc web site web.config anything specific to the existing website (appSettings, connectionStrings, namespaces, membership info, etc). The same applied to the Global.asax files.
  3. I attempted a build and fixed some of the compilation issues
  4. Once the above steps done  I noticed that I got the page not found error when loading default.aspx. This is down to routing, here is the changes I made to the Routing info (located in Global.ascx MVC 3, or App_Start > RouteConfig.cs MVC 4)
With all the above steps taken  the site loaded and working as expected , I now have a ASP.NET Web Forms and ASP.NET MVC hybrid. I am sure there are probably easier ways of accomplishing this task, but I tried other methods and failed.
Hopefully someone finds this useful.

Comments

Popular posts from this blog

Email Sending through O365 using OAuth Protocol

IISRESET vs App Pool Recycling ?

Deploy .Net6.0 Web api with docker