如何使 AppDomain 中的 ASP.NET 程序集保持活动状态? [英] How to keep ASP.NET assemblies in AppDomain alive?

查看:30
本文介绍了如何使 AppDomain 中的 ASP.NET 程序集保持活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:我有一个使用 Web 部署项目部署的 n 层企业 ASP.NET 应用程序.所有层都生成由 ASP.NET 应用程序使用的独立程序集.

Scenario: I've an n-Tier enterprise ASP.NET application deployed using Web Deployment Projects. All tiers produce independent assemblies that is consumed by the ASP.NET application.

问题:当我运行应用程序时.部署后第一次在内存中加载依赖程序集需要大量时间.但是一旦加载了它的快速照明应用程序.如果没有用户访问该应用程序,IIS 会从内存中卸载程序集,并且当用户尝试在以后的实例上访问该应用程序时,它会再次加载所有程序集,加载时间与加载时间相同第一次这样做.

Problem: When I run the app. for the first time after deployment it takes lot of time to load dependent assemblies in memory. But once loaded its lighting fast app. In case if there are no users accessing the app, IIS unloads the assemblies from the memory and when a user tried to access the app on a later instance it goes on loading all the assemblies once again taking the same amount of time to load as it takes to do so for the first time.

我正在寻找一种解决方案,使我能够将我的程序集加载到内存中,并持续覆盖程序集的易失性,从而实现内存驻留.

或任何其他解决方案,让我的用户愉快地使用解决上述问题的应用程序.

Or any other solution that lets my users happily use the app resolving the mentioned problem.

推荐答案

IIS 6 中,转到应用程序池部分,然后右键单击 > 托管 ASP.NET 的池上的属性有问题的申请.转到性能"选项卡并取消选中空闲后关闭工作进程:"

In IIS 6, go to the Application Pools section, and right-click > Properties on the pool which hosts the ASP.NET application in question. Go to the Performance tab and uncheck "Shutdown worker processes after being idle for:"

IIS 7 中,转到连接"窗格并找到应用程序池",然后为托管您的应用程序的池选择高级设置".找到空闲超时"属性并将其设置为0"(这将禁用它).

In IIS 7, go to the Connections pane and find Application Pools, and select Advanced Settings for the pool which hosts your application. Find the "Idle Timeout" property and set it to "0" (this disables it).

默认值为 20 分钟不活动.通过取消选中该框,一旦您的 AppDomain工作进程,它永远不会死(除非你杀死进程或当然的东西).默认情况下,IIS 将 回收进程 当它达到某个限制时,例如内存上限,但它也将启动一个新的并逐步转移"所有传入的请求,直到旧的请求未被使用,以尽量减少中断.

The default is 20 minutes of inactivity. By unchecking the box, once your AppDomain is loaded by the worker process, it will never die (unless you kill the process or something of course). By default, IIS will recycle the process when it reaches some limit, such as a memory cap, but it will also start a new one and "phase over" all incoming requests until the old one is unused, so as to minimize disruption.

我还编写了一个小的 c# 类,它可以让您的 ASP.NET 应用程序保持活力(备用存档版本)在正常情况下情况.由于它在应用程序内运行,显然它不能阻止 IIS 或其他任何东西明确终止进程,但它会使应用程序保持热"状态,例如该应用程序的空闲时间永远不会长到让 IIS 决定将其关闭.

I've also written a small c# class which will keep your ASP.NET application alive (alternate archived version) under normal circumstances. Since it runs within the application, obviously it can't stop IIS or anything else from explicitly killing the process, but it will keep the application "hot", e.g. the app will never go idle long enough for IIS to decide to shut it off.

如果您不能直接控制 IIS 配置(例如共享主机),最好的办法是在单独的系统上运行一个小型应用程序 - 例如,一个永远在线的工作站 - 它每隔 x 次访问您的站点分钟,以防止应用程序池超时.没什么特别的 - 一个简单的 WebRequest 和一个 while()控制台应用程序中的循环就可以了.

If you do not have direct control over your IIS configuration (shared host, for example) your best bet is to have a small application running on a separate system - say, an always-on workstation - which hits your site every x minutes to keep the application pool from timing out. Nothing fancy - a simple WebRequest and a while() loop in a console application will do.

这篇关于如何使 AppDomain 中的 ASP.NET 程序集保持活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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