Asp.net WebForms app that runs MVC in a subfolder

 ̄綄美尐妖づ 提交于 2019-12-21 17:57:46

问题


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?

回答1:


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?



来源:https://stackoverflow.com/questions/3378666/asp-net-webforms-app-that-runs-mvc-in-a-subfolder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!