views:

81

answers:

1

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

  • few *.aspx files in root folder that run as WebForms application (no routing involved)
  • a subfolder ie FormsFolder that has other files and subfolders in it that run as a regular web forms application
  • a subfolder MvcFolder that has a normal structure of an Asp.net MVC application and runs it's content as one as well
  • Routes are registered using an HttpModule instead in global.asax
  • Both parts of this application (or both apps if you prefer) must run under the same IIS application (so in there are two apps, only virtual directory can be used)

Here are some questions:

  1. Is this scenario at all possible?
  2. Is it possible to attach an MVC application to a WebForms app without any code change of the later? Configuration can be changed but should be avoided as much as possible if subfolder configuration can be used.
  3. Is it possible to configure UrlRoutingModule to run only when requests are made for a particular subfolder but is not configured in other parts of the app?
+3  A: 

This is possible, in fact, as they will be running in the context of the same application, it shouldn't be an issue. What you may have to do is register yourself a new ViewEngine that points to /MvcFolder/Views for your views. The root of the application will still be ~/ so you may need to ensure your routes take this into consideration, e.g. by having something like 'MvcFolder/{controller}/{action}' etc as routing rules.

MVC and WebForms apps can run side by side with no issues. The UrlRoutingModule will match any rules before the request reaches the WebForms HttpHandler, so be wary of routing any rules such as 'DoSomething.aspx', as this will be intercepted by MVC.

If you choose not to register the UrlRoutingModule in the base web.config, you can probably register it in the /MvcFolder/web.config file. This will stop any routes being matched outside the /MvcFolder.

Why are you registering the rules in a HttpModule? These will run for each request, so are you sure you are not registering rules in each request unnecessarily?

Matthew Abbott
Oh good idea about a custom view engine.
Robert Koritnik
I'm registering rules in a module, because I'm not allowed to change webform's application global.asax file and class. My module works in a way so it registers routes **only once** and not always. Check out this question and you'll see, that there is actually a possibility to intercept application start event in an http module even though it's not directly supported. http://stackoverflow.com/questions/3370839
Robert Koritnik