IIS应用程序池回收+石英计划
我正在IIS 7.5上运行一个Web应用程序,它需要偶尔回收(否则内存使用不再处理,我正在研究的东西!)。
当它再循环时,它实际上不会运行,直到另一个请求进入,石英不会运行。
有没有办法让IIS在回收应用程序池后立即自动启动1个工作流程,以确保石英始终在线?
是!
-
编辑C:\ Windows \ System32 \ inetsrv \ config \ applicationHost.config以包含:
-
声明应该作为您网站的“热身”运行的内容
-
使用您想要的任何“预热”逻辑配置您的应用程序:
public class PreWarmCache : System.Web.Hosting.IProcessHostPreloadClient { public void Preload(string[] parameters) { // Perform initialization and cache loading logic here... } }
注意:如果您需要的只是w3wp.exe进程存在,我相信只需要第1步。 如果你还需要其他项目(比如某些东西要加载到内存中),那么也会使用第2步和第3步。
从IIS 8.0开始,可以选择模拟对根页面的请求,从而进行完整的应用程序初始化:应用程序池高级设置 – > Preload enabled = true。
当然,startMode应该是AlwaysRunning。
有关如何启用此function的更多详细信息,请参见此处 。
我解决了这个问题。 虽然Stephen的回答将使应用程序保持运行,但在Spring.Net环境中,框架不会启动,Quartz也无法运行。 我整理了一个IProcessHostPreloadClient实现,它将触发对应用程序的实际请求,以便让所有机器运行。 这也发布在我的博客上 :
public class Preloader : System.Web.Hosting.IProcessHostPreloadClient { public void Preload(string[] parameters) { var uris = System.Configuration.ConfigurationManager .AppSettings["AdditionalStartupUris"]; StartupApplication(AllUris(uris)); } public void StartupApplication(IEnumerable uris) { new System.Threading.Thread(o => { System.Threading.Thread.Sleep(500); foreach (var uri in (IEnumerable )o) { var client = new System.Net.WebClient(); client.DownloadStringAsync(uris.First()); } }).Start(uris); } public IEnumerable AllUris(string userConfiguration) { if (userConfiguration == null) return GuessedUris(); return AllUris(userConfiguration.Split(' ')).Union(GuessedUris()); } private IEnumerable GuessedUris() { string path = System.Web.HttpRuntime.AppDomainAppVirtualPath; if (path != null) yield return new Uri("http://localhost" + path); } private IEnumerable AllUris(params string[] configurationParts) { return configurationParts .Select(p => ParseConfiguration(p)) .Where(p => p.Item1) .Select(p => ToUri(p.Item2)) .Where(u => u != null); } private Uri ToUri(string value) { try { return new Uri(value); } catch (UriFormatException) { return null; } } private Tuple ParseConfiguration(string part) { return new Tuple(IsRelevant(part), ParsePart(part)); } private string ParsePart(string part) { // We expect IPv4 or MachineName followed by | var portions = part.Split('|'); return portions.Last(); } private bool IsRelevant(string part) { var portions = part.Split('|'); return portions.Count() == 1 || portions[0] == System.Environment.MachineName || HostIpAddresses().Any(a => a == portions[0]); } private IEnumerable HostIpAddresses() { var adaptors = System.Net.NetworkInformation .NetworkInterface.GetAllNetworkInterfaces(); return adaptors .Where(a => a.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up) .SelectMany(a => a.GetIPProperties().UnicastAddresses) .Where(a => a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) .Select(a => a.Address.ToString()); } }
或者您可以简单地修改Global.asax中的“Application_Start”方法以确保Quortz正在运行。
- FindControl和动态创建控件的麻烦
- 服务器提交了协议违规。 Section =使用tor代理时的ResponseStatusLine
- 在ASP.NET中的代码隐藏中读取动态生成的HTML元素值
- ASP.NET 5 EntityFramework.Core 7.0.0-rc1-final issue – 编译器想要引用7.0.0.0,但未找到
- 如何更改asp.net应用程序的时区
- 如何将List <List >转换为DataTable
- 从ASP.NET Web处理程序(.ashx)下载文件时的error handling
- inheritance的属性不会出现在asmx文件的soap示例中
- 从ASP.NET MVC中的表单发布到另一个模型