公共类中的会话变量? [英] Session variables in a Public Class?

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

问题描述




如何在公共类中访问会话变量?

我尝试过下面的代码,但是我收到服务器错误对象引用不是

设置为对象的实例。

System.Web.HttpContext.Current.Session.Add(" myKey" ,myValue)

Dim a As String

a = System.Web.HttpContext.Current.Session.Item(" myKey")


谢谢,

Thomas Andersson

Hi,

How can I access a session variable within a Public Class?
I have tried the below code, but I get a server error "Object reference not
set to an instance of an object".

System.Web.HttpContext.Current.Session.Add("myKey" , "myValue")
Dim a As String
a = System.Web.HttpContext.Current.Session.Item("myKey ")

Thanks,
Thomas Andersson

推荐答案

" Thomas Andersson" < Thomas An*******@discussions.microsoft.com >写在

消息新闻:5C ********************************** @ microsof t.com ...


试试这个:


System.Web.HttpContext.Current.Session(" myKey")=" ; myValue"

Dim a As String

a = System.Web.HttpContext.Current.Session(" myKey")。To String()

"Thomas Andersson" <Thomas An*******@discussions.microsoft.com> wrote in
message news:5C**********************************@microsof t.com...

Try this:

System.Web.HttpContext.Current.Session("myKey") = "myValue"
Dim a As String
a = System.Web.HttpContext.Current.Session("myKey").To String()





感谢您的建议,但此代码生成相同的错误对象

引用未设置为对象的实例。


祝你好运,

Thomas Andersson


" ; Mark Rae写道:
Hi,

Thank you for your suggestion, but this code generate the same error "Object
reference not set to an instance of an object".

Best regards,
Thomas Andersson

"Mark Rae" wrote:
" Thomas Andersson" < Thomas An*******@discussions.microsoft.com >在消息中写道:5C ********************************** @ microsof t.com。 ..

试试这个:

System.Web.HttpContext.Current.Session(" myKey")=" myValue"
Dim a As String
a = System.Web.HttpContext.Current.Session(" myKey")。To String()
"Thomas Andersson" <Thomas An*******@discussions.microsoft.com> wrote in
message news:5C**********************************@microsof t.com...

Try this:

System.Web.HttpContext.Current.Session("myKey") = "myValue"
Dim a As String
a = System.Web.HttpContext.Current.Session("myKey").To String()



"托马斯安德森 <钍************* @ discussions.microsoft.com>写在

消息新闻:C6 ********************************** @ microsof t.com ...
"Thomas Andersson" <Th*************@discussions.microsoft.com> wrote in
message news:C6**********************************@microsof t.com...
感谢您的建议,但此代码生成相同的错误
对象
引用未设置为实例对象"。
Thank you for your suggestion, but this code generate the same error
"Object
reference not set to an instance of an object".




错误发生在第1行还是第3行?



Does the error occur on the 1st or 3rd line?


这篇关于公共类中的会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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