6

For regular assemblies one can use MEF to load assemblies dynamically. If a live update is required of those assemblies, the recommendation is to use AppDomains to host the dynamic assemblies (potentially one can use Managed Add-in Framework (MAF)). When requiring an update, the appdomain is stopped, the assemblies are updated and the appdomain is reloaded.

What about assemblies that are loaded by ASP .NET that contain that code behind classes? How can I update them without forcing a restart of the main appdomain. Is it possible to host some of my pages in a dynamic appdomain? How would you do that? Can this appdomain share login token and authentication stuff so the user doesn't have to re-login?

Thanks

4

2 回答 2

2

MEF 不支持 AppDomain 隔离,因此很遗憾,即使在重组期间,那些先前已加载的程序集仍会加载到主 Web 应用程序 AppDomain 中。在 ASP.NET 中需要解决两件事:

  1. 对物理文件(例如 .aspx、.cshtml 等)的任何更改,或对配置文件 (.config) 的任何更改,或对 \bin 目录的任何更改都将导致应用程序被回收。这是由于两件事,页面/配置的文件监视和 \bin 目录的文件监视(这是因为默认情况下 ASP.NET 使用文件的卷影复制 - 这是推荐的)。

  2. 要在另一个 AppDomain 中使用 MEF 将需要大量的跨域通信,无论是通过序列化还是MarshalByRef,我只是认为这不会是一个干净的实现。也不确定如何触发BuildProvider用于在另一个 AppDomain 中动态编译页面的实例。

我想知道你是不是想太多了。从 IIS6 开始,HTTP.SYS 管理了传入请求到相应网站的路由,这是在内核级别处理的。即使主应用程序确实重新启动(有多种原因可以),也不会丢弃任何请求,它只会在传递请求之前排队等待新的工作进程。当然,从用户的角度来看,他们可能会注意到等待新应用程序重新启动的一些空闲时间,但实际上,您将多久进行一次这些更改?

许多应用程序设计都存在过度工程的问题。您可能希望针对每个场景进行设计,但实际上维护一个简单但可扩展的系统更容易。在我看来,想要做你指定的事情将被归类为过度工程。把事情简单化。

于 2011-09-29T07:31:54.523 回答
0

使用会话“StateServer”将保留您在应用程序池回收之间的身份验证(由文件更新引起)。

对于您的实际问题:

  • 在您的网站之外创建一个您的应用程序池可以访问的文件夹。
  • 把你的新组件放在那里
  • 具有读取文件夹并将程序集加载到当前应用程序域的任务/线程/Web 服务
    • 创建实例时,应优先使用较新版本的程序集

我猜你的问题是说这种方法不起作用?你遇到了什么错误...

于 2011-10-04T14:10:49.033 回答