Session.isNewSession ...无法理解工作。 [英] Session.isNewSession ...Unable to understand working.

查看:307
本文介绍了Session.isNewSession ...无法理解工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试在我将字符串存储到会话中的应用程序中工作。



会话[  MyString] 





进一步在PageController页面上。



我在页面加载中有如下代码。



如果(!Session.IsNewSession)
{
if (user == null
{
/// /////////这样做......
}

}
else
{
if (会话[ MyVariable]!= null // 这里我总是返回null:(
{
删除();
}
}





可以任意body解释了我什么时候应该执行else部分?其次是我的

会话[ 变量] 

总是ge tting null 以换取其他部分?





谢谢:)

解决方案

嗯。让我们来看看那段代码,我们呢?

 If(!Session.IsNewSession)
{
...
}
else
{
if (会话[ MyVariable]!= null // 这里我总是返回null :(
{
...
}
}

那么,如果这是一个新的Session,你只能直接尝试使用Session变量吗?当teh变量默认为null?你会感到惊讶它们是null。


Hi All,

I am trying to work on an application where i am storing a string into Session like.

Session["MyString"]



Further on the PageController Page.

I have code like below in Page Load.

If(!Session.IsNewSession)
{
    if(user == null)
   {
     ////////////Do this...
    }

}
else
{
  if(Session["MyVariable"] !=null)     //Here I am always returning null :(
    {
     Delete();
     }
}



Can any body explains me that when the else part will be or should be executed?? and secondly why my

Session["Variable"]

always getting null in return in else part?


Thanks :)

解决方案

Um. Lets have a look at that code, shall we?

If(!Session.IsNewSession)
{
...
}
else
{
  if(Session["MyVariable"] !=null)     //Here I am always returning null :(
  {
...
  }
}

So, you only directly try to use the Session variables if this is a new Session? When teh variables will default to null? And you are surprised that they are null...


这篇关于Session.isNewSession ...无法理解工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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