Asp.net WebForms application that launches MVC in a subfolder

Let's say I have an Asp.net WebForms application that has:

  • several * .aspx files in the root folder that run as a WebForms application (without using routing)
  • subfolder i.e. FormsFolder, which has other files and subfolders in it that run like a regular web form application.
  • MvcFolder subfolder that has the normal MVC Asp.net application structure and runs it as one of them
  • Routes are registered using HttpModule instead of global.asax
  • Both parts of this application (or both applications, if you prefer) should work under the same IIS application (therefore, only a virtual directory can be used in two applications)

Here are a few questions:

  • Is this scenario possible?
  • Can I attach an MVC application to a WebForms application without changing the code later? The configuration can be changed, but it should be avoided as much as possible if the configuration of the subfolder can be used.
  • Is it possible to configure UrlRoutingModule to run only when requests are made for a specific subfolder but are not configured in other parts of the application?
+4
source share
1 answer

This is possible, in fact, since they will work in the context of the same application, this should not be a problem. You may need to register a new ViewEngine that points to / MvcFolder / Views for your views. The root of the application will still be ~ /, so you might need your routes to take this into account, for example. having something like "MvcFolder / {controller} / {action}", etc. as the routing rules, etc.

MVC and WebForms applications can work side by side without problems. The UrlRoutingModule module will comply with any rules before the request reaches the WebForms HttpHandler, so be careful in routing any rules such as "DoSomething.aspx" as this will be intercepted by MVC.

If you decide not to register UrlRoutingModule in the base web.config, you can register it in the /MvcFolder/web.config file. This will stop any routes that will be mapped outside of / MvcFolder.

Why are you registering the rules in the HttpModule? They will be executed for each request, so you are sure that you do not register rules in each request unnecessarily?

+4
source

All Articles