Asp.net WebForms app that runs MVC in a subfolder
Let's say I have an Asp.net WebForms application t开发者_如何转开发hat 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 inglobal.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:
- Is this scenario at all possible?
- 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.
- 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?
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?
精彩评论