在子文件夹中运行 MVC 的 Asp.net WebForms 应用程序 [英] Asp.net WebForms app that runs MVC in a subfolder

查看:24
本文介绍了在子文件夹中运行 MVC 的 Asp.net WebForms 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个 Asp.net WebForms 应用程序,它具有:

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

  • 根文件夹中很少有 *.aspx 文件作为 WebForms 应用程序运行(不涉及路由)
  • 一个子文件夹,即 FormsFolder,其中包含作为常规 Web 表单应用程序运行的其他文件和子文件夹
  • 一个子文件夹 MvcFolder,它具有 Asp.net MVC 应用程序的正常结构并同时运行其内容
  • 使用 HttpModule 而不是在 global.asax
  • 中注册路由
  • 此应用程序的两个部分(或两个应用程序,如果您愿意)必须在同一个 IIS 应用程序下运行(因此在有两个应用程序时,只能使用虚拟目录)
  • 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)

这里有一些问题:

  1. 这种情况可能吗?
  2. 是否可以将 MVC 应用程序附加到 WebForms 应用程序而无需更改后者的任何代码?配置可以更改,但如果可以使用子文件夹配置,则应尽可能避免.
  3. 是否可以将 UrlRoutingModule 配置为仅在对特定子文件夹发出请求但未在应用程序的其他部分进行配置时运行?
  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?

推荐答案

这是可能的,事实上,因为它们将在同一个应用程序的上下文中运行,这应该不是问题.您可能需要做的是为自己注册一个新的 ViewEngine,它指向您的视图的/MvcFolder/Views.应用程序的根目录仍然是 ~/所以你可能需要确保你的路由考虑到这一点,例如通过将MvcFolder/{controller}/{action}"等内容作为路由规则.

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 和 WebForms 应用程序可以毫无问题地并行运行.UrlRoutingModule 将在请求到达 WebForms HttpHandler 之前匹配任何规则,因此要小心路由任何规则,例如DoSomething.aspx",因为这会被 MVC 拦截.

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.

如果您选择不在基础 web.config 中注册 UrlRoutingModule,您可能可以在/MvcFolder/web.config 文件中注册它.这将停止在/MvcFolder 之外匹配任何路由.

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.

为什么要在 HttpModule 中注册规则?这些将针对每个请求运行,所以您确定没有在每个请求中不必要地注册规则吗?

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?

这篇关于在子文件夹中运行 MVC 的 Asp.net WebForms 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆