Launch an ASP MVC project from a regular .aspx page

I have an existing ASP.NET website running on .NET 4.5. I need to integrate an ASP MVC 4 project (which is its own full-featured web application), so that when a user navigates to a specific page, the ASP MVC application starts on the page - almost as if it were in an iframe .

In the main solution, I can set up as launch projects, but this is obviously not what I am looking for. Can someone tell me how to do this? I have never used WCF before, but is this what it can be used for? Thanks for all!

+4
source share
1 answer

You can create a hybrid webforms - MVC application.

For this you need:

  • copy the MVC configuration from web.config of the new MVC project into your WebForms application. web.config
  • create standard MVC 4 folders (at least Views, Controllers)
  • reference the necessary assemblies
  • copy the web.config file from the MVC project view to the WebForms project. Views Folder
  • change the routing configuration to ignore routes, including .aspx / .ascx, so that they are processed by web forms and not MVC (do this also for .ashx, .asmx or any other web form artifacts)

So you have one ASP.NET application that supports MVC and WebForms, and uses the same authentication, session, etc.

Then you can do this integration: - create pages that are fully MVC or fully webforms. If you use master pages, you need to create a main page for web forms and a layout for MVC (it can be very difficult or quite simple, depending on its content and design) - create a web form page and integrate MVC pages using partial representations of AJAX and MVC

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

By the way, this is not theoretical ... I have a web application with a lot of pages, areas and views that uses this technique and works flawlessly. I had to redo the design of the main page (layout and CSS) so that both types of pages look the same. I was fortunate enough to have a menu created in the webforms placeholder using an SQL XML query and XSLT, so reusing it in an MVC layout was absolutely simple. You can do something like this on the main page and the MVC layout (I mean visualizing the HTML manually and using it on both pages so that it runs only once)

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

0
source

Source: https://habr.com/ru/post/1479405/


All Articles