ASP.NET MVC 中的静态字段 [英] static field in ASP.NET MVC

查看:33
本文介绍了ASP.NET MVC 中的静态字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ASP.NET MVC 控制器中有带有大对象的静态字段.对于第一个请求,我初始化此字段,它可用于下一个查询.但在等待 10-20 分钟后,该字段为空.有什么想法吗?我使用 ASP.NET MVC 1 和 IIS 7.

I have static field with large object in ASP.NET MVC controller. For the first request i initialize this field and it is available for the next queries. But after waiting 10-20 minutes this field is null. Have any ideas ? I use ASP.NET MVC 1 and IIS 7.

提前谢谢...

推荐答案

您的应用程序池可能正在回收.

Your application pool is probably recycling.

您应该在 application_start 中填充任何这样的全局变量,这样即使池回收,它们也会在后续请求中重新加载.

You should be populating any globals like this in application_start, that way they will be reloaded on subsequent requests, even if the pool recycles.

默认情况下,如果几分钟内没有活动,它将被卸载,导致必须从头开始重新加载应用程序.您可以通过在 IIS 管理中配置应用程序池设置来防止或减少应用程序池回收的发生.

By default if there is no activity for a few minutes it will be unloaded, causing the application to have to be reloaded from scratch. You can prevent or reduce the occurances of the application pool recycling by configuring the application pool settings in IIS Administration.

这篇关于ASP.NET MVC 中的静态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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