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

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

问题描述

让我们说我有一个具有Asp.net的WebForms应用程序:


  • 在根文件夹数* .aspx文件,作为应用程序的WebForms(不涉及路由)运行

  • 的子目录下,即 FormsFolder 的有其他的文件和子文件夹它,作为一个普通的Web窗体应用程序运行

  • 的子目录下的 MvcFolder 的,有一个Asp.net MVC应用程序的正常结构和运行它的内容之一,也是

  • 路线使用注册的的HttpModule 代替的Global.asax

  • (如果你preFER这两个应用或)这个应用程序的两个部分必须在相同的IIS应用程序下运行(所以有两个应用程序,只能使用虚拟目录)

这里有一些问题:


  1. 这是情景在所有可能的?

  2. 是否可以附加一个MVC应用程序到应用程序的WebForms没有后来的任何code修改?结构可以改变,但应避免尽可能如果可以使用子文件夹的配置。

  3. 是否有可能配置 UrlRoutingModule 来,只有当请求特定的子文件夹制成,但在应用程序的其他部分?
  4. 未配置运行

解决方案

这是可能的,事实上,因为他们将在同一应用程序的上下文中运行,它不应该是一个问题。你可能需要做的是自己注册一个新的视图引擎指向/ MvcFolder /浏览次数为您的意见。该应用程序的根仍然是〜/所以你可能需要确保你的路由考虑到这一点,例如由具有类似'MvcFolder / {控制器} / {行动}'等作为路由规则。

MVC和WebForms的应用程序可以没有问题并行运行。请求到达的WebForms的HttpHandler之前UrlRoutingModule将匹配任何规则,所以要谨慎路由的规则,如DoSomething.aspx,因为这将MVC被截获。

如果您选择不注册在基本web.config中的UrlRoutingModule,你也许可以在/MvcFolder/web.config文件注册。这将停止任何路由/ MvcFolder外面被匹配。

你为什么要注册一个HTTP模块的规则?这些都会为每个请求运行,所以你确定你是不是在注册每个请求的规则不必要的?

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?

解决方案

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?

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

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