会话值问题 [英] Problem with Session values

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

问题描述

嗨朋友们,



我正在进行维护项目,我运行项目并等待会话超时,然后点击某个链接然后我就走了通过时钟链接的页面加载找到...



我发现了一些类似下面的代码

Hi Friends,

I'm working on a maintenance project , I ran the project and waited for session timeout and then clicked on some link then I have gone through the Page Load of the clocked link and found...

I've found some code like below

Convert.ToString(Session["MemberStatus"])
   is returning "" ,when i look in Immediate window and 

返回.ToString()

Session["OrganisationType"].ToString()

正在返回null



我的问题是为什么它返回一个而另一个会话空?

或者有什么不同吗?

is retruning null

My question is Why it is returning for one "" and for another session null?
or is there any difference?

推荐答案

它们不是。



第一个使用Convert,它接受 null 参数并按设计将其转换为空字符串。

第二次尝试在 null上调用方法(在本例中为ToString)价值。这不会返回null,而是抛出一个空引用异常,在你的代码中似乎是一个空返回 - 究竟为什么是你的代码的其余部分,我看不到。这样做不是ToString,调用 null 值上的任何方法都会得到相同的结果。
They aren't.

The first one uses Convert, which accepts a null parameter and converts it to an empty string by design.
The second attempts to call a method (in this case ToString) on a null value. This does not return a null, but instead throws a "Null reference exception" whoch in your code appears to be a null return - exactly why is down to the rest of your code, which I can't see. It just isn't ToString that does this, calling any method on a null value will give you the same result.


这篇关于会话值问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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