4

I have an existing ASP.NET web site running on .NET 4.5. I need to integrate an ASP MVC 4 project (which is its own fully-functional web application) into it so that when the user navigates to a certain page, the ASP MVC application is launched within the page - almost as if it were in an iframe.

In the main solution I can set both as startup projects, but this is obviously not what I am looking for. Can someone point me in the direction of how to do this? I have never used WCF before, but is this something that it could be used for? Thanks for anything!

Brett
  • 1,267
  • 1
  • 13
  • 21
  • 1
    I think this can be achived by having proper routing mechanism in place to route and handle your request to display specific view. After all MVC also returns some kind of HTML page. WCF doesnt fit in this situation anyway. – Guanxi May 06 '13 at 19:38

1 Answers1

0

You can create a hybrid webforms - MVC application.

To do this you need to:

  • copy the MVC configuration from the web.config of a new MVC project to your WebForms application web.config
  • create the standard MVC 4 folders (at least Views, Controllers)
  • reference the required assemblies
  • copy the web.config inside Views from the MVC project to the WebForms project Views folder
  • change the routing configuration to ignore routes including .aspx/.ascx, so that they are handled by web forms, and not MVC (do this also for .ashx, .asmx, or whatever other web forms based artifacts)

This way you have a single ASP.NET application which supports MVC and WebForms, and use the same authentication, session, and so on.

Then you can make this kind of integrations: - make pages that are fully MVC or fully webforms. If you're using master pages, you need to create a master page for web forms, and a layout for MVC (this can be very hard or quite easy, depending on its content and design) - make a webforms page and integrate the MVC pages using AJAX and MVC partial views

Aprt frommy comments, this blog entry will help you a lot: Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications

By the way, this is not theoretical... I have a web application with lots of pages, areas, and views, which uses this technique, and it works flawlessly. I had to redo the design of the master page (layout and CSS) so that both kind of pages look alike. I was lucky enough to have a menu rendered in a webforms placeholder using a SQL XML query and an XSLT, so re-using it in the MVC layout was absolutely easy. You can do something similar to this in your master page and MVC layout (I mean rendering the HTML manually, and using it in both pages, so that it's done only once)

You can take some time to get it to work, but it's worth the effort.

JotaBe
  • 38,030
  • 8
  • 98
  • 117