问题描述
我使用以下code会话管理。
I am using following code for session management.
public class MyClass
{
public static int SomeProperty
{
get { return (int)HttpContext.Current.Session["MyID"]; }
set { HttpContext.Current.Session["MyID"] = value; }
}
}
问题是,一旦在一段时间我得到未将对象引用设置到对象的实例。在 {返回(INT)HttpContext.Current.Session [身份识别码]; }
,虽然我知道的事实,MYID在会议上被设置。在我看来,由于某种原因该会话被销毁。任何想法,为什么能够发生?
Problem is once in a while I get "Object reference not set to an instance of an object." on get { return (int)HttpContext.Current.Session["MyID"]; }
, although I know for fact that MyID was been set in session. Seem to me that for some reason that session is destroyed. Any ideas why that can happen?
我在web.config中会话状态定义没有这使我相信,这是InProc服务器的情况下
I have nothing defined for session state in web.config which leads me to believe that this is a case of InProc server
推荐答案
InProc会话状态都受的AppDomain回收。每次你改变网站的code或配置的时候,这可能发生。 IIS还可以定时自动回收,以时间了。
InProc session state is subject to appDomain recycles. Every time you change the site's code or config, this can happen. IIS can also automatically recycle it from time to time, too.
您必须始终认为它可能是零,并相应地处理它。
You must always assume it could be null, and handle it accordingly.
这篇关于失去我的会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!