Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Session 会话变量在一段时间后变为null_Session - Fatal编程技术网

Session 会话变量在一段时间后变为null

Session 会话变量在一段时间后变为null,session,Session,我已经开发了一个web应用程序,它将执行一些图像的幻灯片放映 图像正在完美地滚动…但经过一段时间后它停止了…我从日志中发现,我的会话变量here session[Username]正在变为null。我的代码是 [WebMethod] [ScriptMethod] public static string GetNextImage() { try { if (HttpContext.Current.Sessio

我已经开发了一个web应用程序,它将执行一些图像的幻灯片放映

图像正在完美地滚动…但经过一段时间后它停止了…我从日志中发现,我的会话变量here session[Username]正在变为null。我的代码是

   [WebMethod]
    [ScriptMethod]
    public static string GetNextImage()
    {
        try
        {

            if (HttpContext.Current.Session["Username"] != null)
            {
                string username = HttpContext.Current.Session["Username"].ToString();
                RollingScreenBAL bal = new RollingScreenBAL();
                DetailsForSlideShow[] details = bal.GetDetailsForSlideShow(username);
                int count = details.Length;
                int i;

                for (i = 0; i < count; i++)
                {
                    if (HttpContext.Current.Session["Count"] == null)
                    {

                        HttpContext.Current.Session["GraphUrl"] = details[0].GraphUrl;
                        HttpContext.Current.Session["Count"] = i + 1;
                        break;
                    }
                    else
                    {
                        if (Convert.ToInt32(HttpContext.Current.Session["Count"]) == i)
                        {
                            HttpContext.Current.Session["GraphUrl"] = details[i].GraphUrl;
                            if (i == (count - 1))
                            {
                                HttpContext.Current.Session["Count"] = null;
                            }
                            else
                            {
                                HttpContext.Current.Session["Count"] = i + 1;
                            }
                            break;

                        }
                    }


                }

            }
            return HttpContext.Current.Session["GraphUrl"].ToString();



        }
        catch (Exception ex)
        {

            ConfigurationManager configMgr = new ConfigurationManager();
            string traceFilePath = configMgr.GetTraceFilePath();
            StreamWriter traceFile = new StreamWriter(traceFilePath, true);
            traceFile.WriteLine(ex.Message + "\n" + ex.StackTrace + "Current User is  " + **HttpContext.Current.Session["Username"])**;
            traceFile.Close();
            return ex.Message;
        }
    } 

HttpContext.Current.Session[Username]会话值将变为null。有人能告诉我为什么会变为null吗?提前感谢…

当会话超时且未重新建立/重新初始化时,会话变量将变为null,或者,当您在会话字典中将特定项显式设置为null时。

实际上,图像仅在几秒钟的时间范围内滚动…但是会话值默认将持续20分钟…因此我认为会话超时不能成为我的情况下的原因。。。。